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)


Start a new thread

Cancel reply
Markdown. Syntax highlighting with <code lang="php"><?php echo "Hello, world!"; ?></code> etc.
DjangoPythonBitcoinTuxDebianHTML5 badgeSaltStackUpset confusedMoneyHackerUpset confusedX.OrggitFirefoxWindowMakerBashIs it worth the time?i3 window managerWagtailContainerNginxSilenceTorWorldInternet securityFont