Created
June 24, 2014 17:41
-
-
Save mm-rtin/5f50adc8a5ecf9554edc to your computer and use it in GitHub Desktop.
Model Manager Boilerplate
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.models.query import QuerySet | |
from django.db import models | |
# WatchMixin | |
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
class WatchMixin(object): | |
pass | |
# WatchQuerySet - allows for model manager chaining | |
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
class WatchQuerySet(QuerySet, WatchMixin): | |
pass | |
# WatchManager | |
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
class WatchManager(models.Manager, WatchMixin): | |
def get_query_set(self): | |
return WatchQuerySet(self.model, using=self._db) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment