Code

Ticket #8119: 8119.diff

File 8119.diff, 2.5 KB (added by isagalaev, 6 years ago)

Patch

Line 
1Index: django/db/models/manager.py
2===================================================================
3--- django/db/models/manager.py (revision 8210)
4+++ django/db/models/manager.py (working copy)
5@@ -54,11 +54,18 @@
6     def get_empty_query_set(self):
7         return EmptyQuerySet(self.model)
8 
9+    def get_full_query_set(self):
10+        """Returns a new QuerySet object containing all records. Subclasses can
11+        override this method to customize queryset instances but it's required
12+        that they return all records.
13+        """
14+        return QuerySet(self.model)
15+
16     def get_query_set(self):
17         """Returns a new QuerySet object.  Subclasses can override this method
18-        to easily customize the behavior of the Manager.
19+        to add custom filters to queryset instances.
20         """
21-        return QuerySet(self.model)
22+        return self.get_full_query_set()
23 
24     def none(self):
25         return self.get_empty_query_set()
26@@ -81,6 +88,12 @@
27     def get(self, *args, **kwargs):
28         return self.get_query_set().get(*args, **kwargs)
29 
30+    def get_full(self, *args, **kwargs):
31+        """Used to access parent related objects ensuring that they're
32+        not affected by any filters.
33+        """
34+        return self.get_full_query_set().get(*args, **kwargs)
35+
36     def get_or_create(self, **kwargs):
37         return self.get_query_set().get_or_create(**kwargs)
38 
39Index: django/db/models/fields/related.py
40===================================================================
41--- django/db/models/fields/related.py  (revision 8210)
42+++ django/db/models/fields/related.py  (working copy)
43@@ -2,7 +2,6 @@
44 from django.db.models import signals, get_model
45 from django.db.models.fields import AutoField, Field, IntegerField, PositiveIntegerField, PositiveSmallIntegerField, FieldDoesNotExist
46 from django.db.models.related import RelatedObject
47-from django.db.models.query import QuerySet
48 from django.db.models.query_utils import QueryWrapper
49 from django.utils.translation import ugettext_lazy, string_concat, ungettext, ugettext as _
50 from django.utils.functional import curry
51@@ -239,7 +238,7 @@
52                 params = {'%s__pk' % self.field.rel.field_name: val}
53             else:
54                 params = {'%s__exact' % self.field.rel.field_name: val}
55-            rel_obj = QuerySet(self.field.rel.to).get(**params)
56+            rel_obj = self.field.rel.to._default_manager.get_full(**params)
57             setattr(instance, cache_name, rel_obj)
58             return rel_obj
59