Anyone?
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
As other have already written, it's not possible to filter on the
result of a model method.
There's at least one thing you can do differently to speed up this method a bit.
> def myview(request):
> q = Article.objects.all()
> for item in q:
> if not item.permission.can_view_article(request.user):
> q = q.exclude(item.pk)
>
Everytime you call exclude (btw, this should be q =
q.exclude(pk=item.pk), no?), a new queryset instance is constructed.
This is probably not neccessary. You could do this instead, assuming
permission is another database model linked with a foreign key:
articles = [article for article in
Article.objects.all().select_related('permission') if
article.permission.can_view_article(request.user)]
At least you'll hit the article table only once this way.