On Sat, May 16, 2009 at 5:28 PM, ringemup <[email protected]> wrote:

>
> Contrib.comments references related object primary keys instead of the
> objects themselves, so is there any easy way to filter comments on a
> property of the related model?  For instance, if I have a blog and
> want to retrieve all comments for entries in Category X, is that
> possible through the Django ORM?
>
> Thanks!
> >
>
No, at least not directly, but this is because there's no way to do that at
the backend level.  Generic relations (which is how comments are connected
with objects) work by storing a primary key and a content type, and those
aren't really relational database concepts, however you can do something
like this:

Comment.objects.filter(content_type=ContentType.objects.get_for_model(Entry),
object_pk__in=Entry.objects.filter(category="some category")).

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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to