Hi Jason,

On Monday 22 February 2010 09:57:18 Jason wrote:
> If I already had a QuerySet of Article named articles, how to get a
> QuerySet of Publication by these articles, 
You can use field lookup operator `in` like this:

>>> Publication.objects.filter(
>>>     article_set__id__in = article_qs.values_list('id', flat=True))

Maybe the ORM even accepts article_set__in = article_qs, but I haven't tried.


> and count the articles by
> the Publication?

>>> article_qs.annotate(Count('publications'))

See http://docs.djangoproject.com/en/dev/ref/models/querysets/

Hope this helps.


-- 
Saygılarımla,
Atamert Ölçgen

 -+-
 --+
 +++

www.muhuk.com
mu...@jabber.org

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.

Reply via email to