I need to have all my models inherit this manager (Haven't tested this manager and it may be ridiculous so I'm completely open to suggestion/criticism on it as well):
class AccountFilterManager(models.Manager):
def __init__(self, account=None, *args, **kwargs):
super(AccountFilterManager, self).__init__(*args, **kwargs)
self.account = account # account of course will be an instance of Account(models.Model)
def get_query_set(self):
if self.account:
return super(AccountManager,self).get_query_set().filter(account=self.account)
You can see what I'm trying to do. limit the need to filter out everywhere based on what account I'm dealing with.
What would be the best way to get this manager to work with all my models? Abstract base model with it? Also, how am I going to pass in the account variable into it from the view level? Is this all wrong and evil? I've been trying to find a way to conquer this for a week now :(.