Skip to content

Instantly share code, notes, and snippets.

@majgis
Created January 16, 2013 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save majgis/4548563 to your computer and use it in GitHub Desktop.
Save majgis/4548563 to your computer and use it in GitHub Desktop.
Add new QuerySet methods using a Model inner class
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