Skip to content

Instantly share code, notes, and snippets.

@seanmonstar
Created May 26, 2011 22:40
Show Gist options
  • Save seanmonstar/994265 to your computer and use it in GitHub Desktop.
Save seanmonstar/994265 to your computer and use it in GitHub Desktop.
QuerySetManager
class QuerySetManager(models.Manager):
def get_query_set(self):
return self.QuerySet(self.model)
def __getattr__(self, attr, *args):
return getattr(self.get_query_set(), attr, *args)
class PackagesManager(QuerySetManager):
class QuerySet(QuerySet):
def active(self):
pass
def addons(self):
pass
def libraries(self):
pass
def recently_active(self):
pass
Package.objects.active().libraries().recently_active().filter(author=1)
@zalun
Copy link

zalun commented May 26, 2011

would filter by author before recently active make the last one quicker?

@seanmonstar
Copy link
Author

possibly. that is up to how Django executes QuerySets. basically, this just easily adds the methods we add to the manager to be chainable from the QuerySet as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment