Created
June 15, 2011 00:18
-
-
Save bryanchow/1026248 to your computer and use it in GitHub Desktop.
Django QuerySetManager: 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
# Django Query Set Manager | |
# | |
# https://gist.github.com/1026248 | |
from django.db import models | |
class QuerySetManager(models.Manager): | |
""" | |
Enables adding new QuerySet methods using a Model inner class. | |
http://djangosnippets.org/snippets/734/ | |
https://code.djangoproject.com/ticket/15062 | |
""" | |
def get_query_set(self): | |
return self.model.QuerySet(self.model) | |
def __getattr__(self, attr, *args): | |
if attr.startswith('_'): | |
raise AttributeError | |
return getattr(self.get_query_set(), attr, *args) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment