Suppose I have two models:
<code>class One(models.Model):
name = models.CharField(max_length=300, unique=True)
class Two(models.Model):
name = models.CharField(max_length=300, unique=True)
</code>
<code>class One(models.Model):
name = models.CharField(max_length=300, unique=True)
class Two(models.Model):
name = models.CharField(max_length=300, unique=True)
</code>
class One(models.Model):
name = models.CharField(max_length=300, unique=True)
class Two(models.Model):
name = models.CharField(max_length=300, unique=True)
They are not related by a foreign key, and there are reasons to leave it that way in this project.
I want to know the One
instances with a name
that is not in Two
.
Here is the SQL to get that:
<code>select app_one.name
from app_one left join app_two on app_one.name = app_two.name
where app_two.name is null
group by 1;
</code>
<code>select app_one.name
from app_one left join app_two on app_one.name = app_two.name
where app_two.name is null
group by 1;
</code>
select app_one.name
from app_one left join app_two on app_one.name = app_two.name
where app_two.name is null
group by 1;
Is it possible to get that through the ORM, or do I just have to write a query?