Filtering manager for django model, customized by user

Posted by valya on Stack Overflow See other posts from Stack Overflow or by valya
Published on 2010-03-08T08:50:22Z Indexed on 2010/03/08 9:21 UTC
Read the original article Hit count: 547

Hi there!

I have a model, smth like this:

class Action(models.Model): 
    def can_be_applied(self, user):
        #whatever
        return True

and I want to override its default Manager. But I don't know how to pass the current user variable to the manager, so I have to do smth like this:

 [act for act in Action.objects.all() if act.can_be_applied(current_user)]

How do I get rid of it by just overriding the manager?

Thanks.

© Stack Overflow or respective owner

Related posts about django

Related posts about django-managers