Last active
August 29, 2015 14:04
-
-
Save lsemel/2b52ba807975900ce80a to your computer and use it in GitHub Desktop.
Example of chainable django queryset methods (for Django 1.6 and lower)
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 | |
from django.db.models import query | |
class PersonQuerySet(query.QuerySet): | |
def some_query(self): | |
return self.filter(...) | |
def some_other_filter(self): | |
return self.filter(...) | |
class PersonManager(models.Manager): | |
def get_query_set(self): | |
return PersonQuerySet(self.model) | |
def __getattr__(self, name, *args): | |
if name.startswith("_"): # or at least "__" | |
raise AttributeError | |
return getattr(self.get_query_set(), name, *args) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment