mirror of
https://github.com/Hopiu/django-model-utils.git
synced 2026-03-16 20:00:23 +00:00
use manager_from for inheritance-casting
This commit is contained in:
parent
a2c67934ed
commit
396dd9274f
2 changed files with 4 additions and 11 deletions
|
|
@ -6,7 +6,7 @@ from django.db.models.manager import Manager
|
|||
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 = {}
|
||||
|
|
@ -27,14 +27,6 @@ class InheritanceCastQuerySet(QuerySet):
|
|||
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:
|
||||
|
|
|
|||
|
|
@ -6,7 +6,8 @@ from django.utils.translation import ugettext_lazy as _
|
|||
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
|
||||
|
||||
|
|
@ -20,7 +21,7 @@ class InheritanceCastModel(models.Model):
|
|||
"""
|
||||
real_type = models.ForeignKey(ContentType, editable=False, null=True)
|
||||
|
||||
objects = InheritanceCastManager()
|
||||
objects = manager_from(InheritanceCastMixin)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.id:
|
||||
|
|
|
|||
Loading…
Reference in a new issue