On Tue, Mar 24, 2009 at 4:26 PM, Konstantin S <ktechli...@gmail.com> wrote:
> > > > On Mar 24, 11:13 pm, 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')) > > > > Yes, but I want to be sure that it uses JOIN syntax. > > > > It's not possible to do that using the ORM, you'll need to use some raw sql. 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 -~----------~----~----~----~------~----~------~--~---