2012/11/30 Shai Berger <s...@platonix.com>

> On Friday 30 November 2012, Marek Brzóska wrote:
> > Has the matter been completely put away?
> >
> > I would like to bring it up again.
> >
> > I have Articles and Categories. An Article belongs to Categories:
> >
> > class Category(model):
> >   pass
> > class Article(model):
> >   category = ManyToManyField(Category)
> >   status = CharField(max_length=10)
> >
> > Now I want all categories with articles that have status different than
> > "archived".
> >
> > I cannot do this with django's ORM!
> >
>
> live_articles = Article.objects.exclude(status="archived")
> live_cats = Category.objects.filter(article__in=live_articles)
>
> Doesn't this do the trick for you?
>
It does. But I have to write two ORM queries instead of one, even though I
mean one DB operation. So it is kinda "trick" as you named it. Not very
bad, but still - could be better without so much cost, I believe.



-- 
Marek Brzóska

brzoskama...@gmail.com

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to