On Aug 16, 3:17 am, bruno desthuilliers <bruno.desthuilli...@gmail.com> wrote: > > Of course. As the error message says, 'c' is here a queryset, not a > model object. If you want to retrieve a single model object, you have > to use manager.get, not manager.filter, ie:
Sorry about that brain fart - of course you're right - I just needed get() instead of filter() there. Must have been late :) > You won't be able to do this in a single SQL query. A Q&D solution > might be: > > def recent_comments(request): > comments = Comment.objects.all().order_by('-id') > recent_comments = [] > for comment in comments: > if len(recent_comments) == 6: # XXX hardcoded, that's bad > break > content = comment.content_object() > try: > if content.publish: > recent_comments.append(comment) > except AttributeError > # content has no 'publish' attribute > pass > return dict(recent_comments=recent_comments) I almost did get it down to a single query, but custom Model Managers on the related content_object made things even more complicated, so I settled on a custom list much like your example instead, which works nicely. Thanks much! ./s -- 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.