Skip to content

Instantly share code, notes, and snippets.

@mm-rtin
Created June 24, 2014 17:41
Show Gist options
  • Save mm-rtin/5f50adc8a5ecf9554edc to your computer and use it in GitHub Desktop.
Save mm-rtin/5f50adc8a5ecf9554edc to your computer and use it in GitHub Desktop.
Model Manager Boilerplate
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