Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
  • Loading branch information...
commit b763412aa4639d3e769eca4eab44835324e1b8d2 1 parent 662eea1
@spookylukey spookylukey authored
Showing with 7 additions and 22 deletions.
  1. +7 −22 django/db/models/fields/related.py
View
29 django/db/models/fields/related.py
@@ -9,7 +9,7 @@
from django.db.models.deletion import CASCADE
from django.utils.encoding import smart_unicode
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 import forms
@@ -386,8 +386,7 @@ def __get__(self, instance, instance_type=None):
if instance is None:
return self
- manager = self.create_manager(self.related.model._default_manager.__class__)
- return manager(instance)
+ return self.related_manager_cls(instance)
def __set__(self, instance, value):
if instance is None:
@@ -400,24 +399,11 @@ def __set__(self, instance, value):
manager.clear()
manager.add(*value)
- def delete_manager(self, instance):
- """
- Returns a queryset based on the related model's base manager (rather
- than the default manager, as returned by __get__). Used by
- Model.delete().
- """
- 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__
+ @cached_property
+ def related_manager_cls(self):
+ # Dynamically create a class that subclasses the related model's default
+ # manager.
+ superclass = self.related.model._default_manager.__class__
rel_field = self.related.field
rel_model = self.related.model
attname = rel_field.rel.get_related_field().attname
@@ -489,7 +475,6 @@ def clear(self):
clear.alters_data = True
return RelatedManager
- create_manager = memoize(create_manager, {}, 2)
def create_many_related_manager(superclass, rel):
Please sign in to comment.
Something went wrong with that request. Please try again.