I'm trying to figure out why this works:

>>> comments = Comment.objects.all()
>>>[c.content_object for c in comments]

[returns a list of the objects the comments are attached to]

But this doesn't:

>>> c = Comment.objects.filter(id=111)
>>> c
[<Comment: Related object name here ...>]
>>> c.content_object
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: 'QuerySet' object has no attribute 'content_object'

The problem I'm trying to solve is that I've got a context processor
that retrieves recent comments:

def recent_comments(request):
    return {'recent_comments': Comment.objects.filter().order_by('-id')
[:6]}

But if an item has been unpublished but still has comments attached to
it, it crashes. So I want to alter the query in the content processor
to only grab comments on items that have publish=True. So far I've
been unsuccessful - I get a crash similar to the one above.

Thanks for a clue.
Scot

-- 
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