Commits

Carl Meyer  committed 413d165

use manager_from for inheritance-casting

  • Participants
  • Parent commits 548c3fc

Comments (0)

Files changed (2)

File model_utils/managers.py

 from django.db.models.query import QuerySet
 
 
-class InheritanceCastQuerySet(QuerySet):
+class InheritanceCastMixin(object):
     def cast(self):
         results = tuple(self.values_list('pk', 'real_type'))
         type_to_pks = {}
         return children
 
 
-class InheritanceCastManager(models.Manager):
-    def cast(self):
-        return self.get_query_set().cast()
-
-    def get_query_set(self):
-        return InheritanceCastQuerySet(self.model)
-
-
 class QueryManager(models.Manager):
     def __init__(self, *args, **kwargs):
         if args:

File model_utils/models.py

 from django.db.models.fields import FieldDoesNotExist
 from django.core.exceptions import ImproperlyConfigured
 
-from model_utils.managers import InheritanceCastManager, QueryManager
+from model_utils.managers import manager_from, InheritanceCastMixin, \
+    QueryManager
 from model_utils.fields import AutoCreatedField, AutoLastModifiedField, \
     StatusField, MonitorField
 
     """
     real_type = models.ForeignKey(ContentType, editable=False, null=True)
 
-    objects = InheritanceCastManager()
+    objects = manager_from(InheritanceCastMixin)
 
     def save(self, *args, **kwargs):
         if not self.id: