Changed internal storing of abstract and concrete managers to be in a single list.
This commit prepares the internal manager layout to be serialized by migrations; refs #23822.
This commit is contained in:
parent
7c1f3901bc
commit
e37ab311fc
|
@ -1225,8 +1225,7 @@ class Model(six.with_metaclass(ModelBase)):
|
||||||
""" Perform all manager checks. """
|
""" Perform all manager checks. """
|
||||||
|
|
||||||
errors = []
|
errors = []
|
||||||
managers = cls._meta.concrete_managers + cls._meta.abstract_managers
|
for __, manager, __ in cls._meta.managers:
|
||||||
for __, __, manager in managers:
|
|
||||||
errors.extend(manager.check(**kwargs))
|
errors.extend(manager.check(**kwargs))
|
||||||
return errors
|
return errors
|
||||||
|
|
||||||
|
|
|
@ -62,6 +62,7 @@ class BaseManager(object):
|
||||||
super(BaseManager, self).__init__()
|
super(BaseManager, self).__init__()
|
||||||
self._set_creation_counter()
|
self._set_creation_counter()
|
||||||
self.model = None
|
self.model = None
|
||||||
|
self.name = None
|
||||||
self._inherited = False
|
self._inherited = False
|
||||||
self._db = None
|
self._db = None
|
||||||
self._hints = {}
|
self._hints = {}
|
||||||
|
@ -69,12 +70,8 @@ class BaseManager(object):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
""" Return "app_label.model_label.manager_name". """
|
""" Return "app_label.model_label.manager_name". """
|
||||||
model = self.model
|
model = self.model
|
||||||
opts = model._meta
|
|
||||||
app = model._meta.app_label
|
app = model._meta.app_label
|
||||||
manager_name = next(name for (_, name, manager)
|
return '%s.%s.%s' % (app, model._meta.object_name, self.name)
|
||||||
in opts.concrete_managers + opts.abstract_managers
|
|
||||||
if manager == self)
|
|
||||||
return '%s.%s.%s' % (app, model._meta.object_name, manager_name)
|
|
||||||
|
|
||||||
def check(self, **kwargs):
|
def check(self, **kwargs):
|
||||||
return []
|
return []
|
||||||
|
@ -116,6 +113,8 @@ class BaseManager(object):
|
||||||
def contribute_to_class(self, model, name):
|
def contribute_to_class(self, model, name):
|
||||||
# TODO: Use weakref because of possible memory leak / circular reference.
|
# TODO: Use weakref because of possible memory leak / circular reference.
|
||||||
self.model = model
|
self.model = model
|
||||||
|
if not self.name:
|
||||||
|
self.name = name
|
||||||
# Only contribute the manager if the model is concrete
|
# Only contribute the manager if the model is concrete
|
||||||
if model._meta.abstract:
|
if model._meta.abstract:
|
||||||
setattr(model, name, AbstractManagerDescriptor(model))
|
setattr(model, name, AbstractManagerDescriptor(model))
|
||||||
|
@ -127,12 +126,11 @@ class BaseManager(object):
|
||||||
if (not getattr(model, '_default_manager', None) or
|
if (not getattr(model, '_default_manager', None) or
|
||||||
self.creation_counter < model._default_manager.creation_counter):
|
self.creation_counter < model._default_manager.creation_counter):
|
||||||
model._default_manager = self
|
model._default_manager = self
|
||||||
|
|
||||||
|
abstract = False
|
||||||
if model._meta.abstract or (self._inherited and not self.model._meta.proxy):
|
if model._meta.abstract or (self._inherited and not self.model._meta.proxy):
|
||||||
model._meta.abstract_managers.append((self.creation_counter, name,
|
abstract = True
|
||||||
self))
|
model._meta.managers.append((self.creation_counter, self, abstract))
|
||||||
else:
|
|
||||||
model._meta.concrete_managers.append((self.creation_counter, name,
|
|
||||||
self))
|
|
||||||
|
|
||||||
def _set_creation_counter(self):
|
def _set_creation_counter(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -88,9 +88,10 @@ class Options(object):
|
||||||
self.auto_created = False
|
self.auto_created = False
|
||||||
|
|
||||||
# To handle various inheritance situations, we need to track where
|
# To handle various inheritance situations, we need to track where
|
||||||
# managers came from (concrete or abstract base classes).
|
# managers came from (concrete or abstract base classes). `managers`
|
||||||
self.abstract_managers = []
|
# keeps a list of 3-tuples of the form:
|
||||||
self.concrete_managers = []
|
# (creation_counter, instance, abstract(=True))
|
||||||
|
self.managers = []
|
||||||
|
|
||||||
# List of all lookups defined in ForeignKey 'limit_choices_to' options
|
# List of all lookups defined in ForeignKey 'limit_choices_to' options
|
||||||
# from *other* models. Needed for some admin checks. Internal use only.
|
# from *other* models. Needed for some admin checks. Internal use only.
|
||||||
|
@ -110,6 +111,20 @@ class Options(object):
|
||||||
def installed(self):
|
def installed(self):
|
||||||
return self.app_config is not None
|
return self.app_config is not None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def abstract_managers(self):
|
||||||
|
return [
|
||||||
|
(counter, instance.name, instance) for counter, instance, abstract
|
||||||
|
in self.managers if abstract
|
||||||
|
]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def concrete_managers(self):
|
||||||
|
return [
|
||||||
|
(counter, instance.name, instance) for counter, instance, abstract
|
||||||
|
in self.managers if not abstract
|
||||||
|
]
|
||||||
|
|
||||||
def contribute_to_class(self, cls, name):
|
def contribute_to_class(self, cls, name):
|
||||||
from django.db import connection
|
from django.db import connection
|
||||||
from django.db.backends.utils import truncate_name
|
from django.db.backends.utils import truncate_name
|
||||||
|
|
Loading…
Reference in New Issue