Created
August 4, 2015 23:58
-
-
Save rfong/950b48d51bf8439f5aef to your computer and use it in GitHub Desktop.
django object manager
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 Q | |
class MyModelManager(models.Manager): | |
"""Define methods on MyModel.objects.""" | |
def get_queryset(self): | |
return MyModelQuerySet(self.model) | |
def __getattr__(self, name, *args): | |
if name.startswith("_"): | |
raise AttributeError | |
return getattr(self.get_queryset(), name, *args) | |
class MyModel(models.Model): | |
objects = MyModelManager() | |
class MyModelQuerySet(models.query.QuerySet): | |
"""Extend MyModel queryset.""" | |
def dummy(self): | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment