Saturday, April 23, 2011

Re: Django ORM question about lookups that span relationships

> Yes, but while raw() has its uses, it's an interesting question: Is
> there a way to do this with the Django ORM or not? It's always hard to
> write raw queries in a database independent way, so there are good cases
> where you want to avoid raw().

You can, with a subrequest:
Blog.objects.filter(pk__in=Entry.objects.filter(pub_date__lte=date(2011,
4, 1), headline__contains='Lennon').values('blog').distinct())

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate