For example if you need to retrieve all books with zero associated sequences (empty sequences list), then code snippet may looks something like this:
Book.objects.annotate(s_count=Count('sequences')).filter(s_count=0)
May be if you read docs on ManyToMany relations, you'll find more nicer solution.
2011/5/1 А.Р. <4d876b82@gmail.com>
2011/5/1 Oleg Lomaka <...@gmail.com>:
Oh, thanks!
> bs = BookSequence.objects.filter(book__pk=1).select_related()
> for s in bs:
> print s.sequence.name, s.number_in_sequence
Is it possible then to do left/right outer joins, as there may exist
books without
sequences and sequences without books?
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.
No comments:
Post a Comment