Skip to content

Instantly share code, notes, and snippets.

@bryanchow
Created June 15, 2011 00:18
Show Gist options
  • Save bryanchow/1026248 to your computer and use it in GitHub Desktop.
Save bryanchow/1026248 to your computer and use it in GitHub Desktop.
Django QuerySetManager: Add new QuerySet methods using a Model inner class
# 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