Django query on model instance's class

I have an abstract base class that is used by various other models. The problem is that I need the same method that runs a query on all instances of those models, and that the manager isn't accessible via model instances. This is the code I ended up using.

def get_related(self, foo):
    return self.__class__.objects.filter(bar=foo)

# This is the real code
#def get_translation(self, language):
#    return self.__class__.objects.public(language=language).filter(group_id=self. group_id)
Published on June 13, 2011 at 10:13 a.m. by Nicolas and tagged query, Django. You can follow the discussion with the comment feed for this post. Feeling generous? Donate!

0 comments

Start a new thread

Cancel reply
Markdown. Syntax highlighting with <code lang="php"><?php echo "Hello, world!"; ?></code> etc.