On Tue, Mar 24, 2009 at 4:15 PM, Paulo Köch <paulo.k...@gmail.com> wrote:
> > Does that generate a join or a not in? This is very relevant for > performance. > > Cheers, > Paulo Köch > > > > On Tue, Mar 24, 2009 at 20:13, Alex Gaynor <alex.gay...@gmail.com> wrote: > > > > > > On Tue, Mar 24, 2009 at 4:05 PM, Konstantin S <ktechli...@gmail.com> > wrote: > >> > >> Hello! > >> > >> I have two unrelated models that have one common field. > >> > >> class Media(models.Model): > >> title = models.CharField(max_length=500) > >> ... > >> > >> class Link(models.Model): > >> title = models.CharField(max_length=500) > >> ... > >> > >> Now I want to select those objects from the Media model that do not > >> exist in the Link model if we compare them only by 'title' field. In > >> raw SQL it looks like this: > >> > >> select * from Media left join Link on Media.title=Link.title where > >> Link.title is null; > >> > >> Is it possible to make the same thing by Django ORM only ? > >> > >> > > > > So to be clear you want all items from Media for which there isn't a link > > with that title, in the ORM that would look like: > > > > Media.objects.exclude(title__in=Link.objects.values('title')) > > > > Alex > > > > -- > > "I disapprove of what you say, but I will defend to the death your right > to > > say it." --Voltaire > > "The people's good is the highest law."--Cicero > > > > > > > > > > > No, it's done using a subquery. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---