ManyToMany Managers should also look into prefetch cache
This commit is contained in:
parent
edfb083c61
commit
9eb832b048
1 changed files with 8 additions and 1 deletions
|
@ -526,6 +526,9 @@ class ManyRelatedManagerWrapper(RelatedManagerWrapper):
|
||||||
def _get_cache_name(self):
|
def _get_cache_name(self):
|
||||||
return self._obj.prefetch_cache_name
|
return self._obj.prefetch_cache_name
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
return self.model.objects.filter(**self._obj.core_filters)
|
||||||
|
|
||||||
def set(self, objs, author=None):
|
def set(self, objs, author=None):
|
||||||
if author is None:
|
if author is None:
|
||||||
author = self._author
|
author = self._author
|
||||||
|
@ -553,7 +556,11 @@ class ManyRelatedManagerWrapper(RelatedManagerWrapper):
|
||||||
self._changeset.add_m2m_remove(self._obj.instance, name=self._get_cache_name(), value=pk, author=author)
|
self._changeset.add_m2m_remove(self._obj.instance, name=self._get_cache_name(), value=pk, author=author)
|
||||||
|
|
||||||
def all(self):
|
def all(self):
|
||||||
return self.model.objects.filter(**self._obj.core_filters)
|
try:
|
||||||
|
return self.instance._prefetched_objects_cache[self._get_cache_name()]
|
||||||
|
except(AttributeError, KeyError):
|
||||||
|
pass
|
||||||
|
return self.get_queryset().all()
|
||||||
|
|
||||||
def create(self, *args, **kwargs):
|
def create(self, *args, **kwargs):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue