Removed ForeignRelatedObjectsDescriptor.RelatedManager.delete_manager, which has been unused since [14507]
And cleaned up the result, allowing more consistency with the other related descriptors. git-svn-id: http://code.djangoproject.com/svn/django/trunk@16931 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
662eea116f
commit
b763412aa4
|
@ -9,7 +9,7 @@ from django.db.models.query_utils import QueryWrapper
|
||||||
from django.db.models.deletion import CASCADE
|
from django.db.models.deletion import CASCADE
|
||||||
from django.utils.encoding import smart_unicode
|
from django.utils.encoding import smart_unicode
|
||||||
from django.utils.translation import ugettext_lazy as _, string_concat
|
from django.utils.translation import ugettext_lazy as _, string_concat
|
||||||
from django.utils.functional import curry, memoize, cached_property
|
from django.utils.functional import curry, cached_property
|
||||||
from django.core import exceptions
|
from django.core import exceptions
|
||||||
from django import forms
|
from django import forms
|
||||||
|
|
||||||
|
@ -386,8 +386,7 @@ class ForeignRelatedObjectsDescriptor(object):
|
||||||
if instance is None:
|
if instance is None:
|
||||||
return self
|
return self
|
||||||
|
|
||||||
manager = self.create_manager(self.related.model._default_manager.__class__)
|
return self.related_manager_cls(instance)
|
||||||
return manager(instance)
|
|
||||||
|
|
||||||
def __set__(self, instance, value):
|
def __set__(self, instance, value):
|
||||||
if instance is None:
|
if instance is None:
|
||||||
|
@ -400,24 +399,11 @@ class ForeignRelatedObjectsDescriptor(object):
|
||||||
manager.clear()
|
manager.clear()
|
||||||
manager.add(*value)
|
manager.add(*value)
|
||||||
|
|
||||||
def delete_manager(self, instance):
|
@cached_property
|
||||||
"""
|
def related_manager_cls(self):
|
||||||
Returns a queryset based on the related model's base manager (rather
|
# Dynamically create a class that subclasses the related model's default
|
||||||
than the default manager, as returned by __get__). Used by
|
# manager.
|
||||||
Model.delete().
|
superclass = self.related.model._default_manager.__class__
|
||||||
"""
|
|
||||||
manager = self.create_manager(self.related.model._base_manager.__class__)
|
|
||||||
return manager(instance)
|
|
||||||
|
|
||||||
def create_manager(self, superclass):
|
|
||||||
"""
|
|
||||||
Creates the managers used by other methods (__get__() and delete()).
|
|
||||||
"""
|
|
||||||
|
|
||||||
# We use closures for these values so that we only need to memoize this
|
|
||||||
# function on the one argument of 'superclass', and the two places that
|
|
||||||
# call create_manager simply need to pass instance to the manager
|
|
||||||
# __init__
|
|
||||||
rel_field = self.related.field
|
rel_field = self.related.field
|
||||||
rel_model = self.related.model
|
rel_model = self.related.model
|
||||||
attname = rel_field.rel.get_related_field().attname
|
attname = rel_field.rel.get_related_field().attname
|
||||||
|
@ -489,7 +475,6 @@ class ForeignRelatedObjectsDescriptor(object):
|
||||||
clear.alters_data = True
|
clear.alters_data = True
|
||||||
|
|
||||||
return RelatedManager
|
return RelatedManager
|
||||||
create_manager = memoize(create_manager, {}, 2)
|
|
||||||
|
|
||||||
|
|
||||||
def create_many_related_manager(superclass, rel):
|
def create_many_related_manager(superclass, rel):
|
||||||
|
|
Loading…
Reference in New Issue