Created
January 16, 2013 16:26
-
-
Save majgis/4548563 to your computer and use it in GitHub Desktop.
Add new QuerySet methods using a Model inner class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
class QuerySetManager(models.Manager): | |
"""Add new QuerySet methods using a Model inner class | |
Reference: | |
http://djangosnippets.org/snippets/734/ | |
""" | |
def __getattr__(self, name, *args): | |
if name.startswith('_'): | |
raise AttributeError | |
return getattr(self.get_query_set(), name, *args) | |
def get_query_set(self): | |
return self.model.QuerySet(self.model) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment