-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdjango.patch
91 lines (82 loc) · 3.77 KB
/
django.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
Index: django/db/models/manager.py
===================================================================
--- django/db/models/manager.py (revision 13444)
+++ django/db/models/manager.py (working copy)
@@ -48,6 +48,9 @@
super(Manager, self).__init__()
self._set_creation_counter()
self.model = None
+ self.model_attname = None
+ self.related_model_instance = None
+ self.related_model_attname = None
self._inherited = False
def contribute_to_class(self, model, name):
Index: django/db/models/fields/related.py
===================================================================
--- django/db/models/fields/related.py (revision 13444)
+++ django/db/models/fields/related.py (working copy)
@@ -1,3 +1,5 @@
+import copy
+
from django.db import connection, transaction
from django.db.backends import util
from django.db.models import signals, get_model
@@ -250,7 +252,10 @@
# If the related manager indicates that it should be used for
# related fields, respect that.
- rel_mgr = self.field.rel.to._default_manager
+ rel_mgr = copy.copy(self.field.rel.to._default_manager)
+ rel_mgr.model_attname = self.field.rel.related_name
+ rel_mgr.related_model_instance = instance
+ rel_mgr.related_model_attname = self.field.name
if getattr(rel_mgr, 'use_for_related_fields', False):
rel_obj = rel_mgr.get(**params)
else:
@@ -351,8 +356,8 @@
rel_model = self.related.model
class RelatedManager(superclass):
- def get_query_set(self):
- return superclass.get_query_set(self).filter(**(self.core_filters))
+ def get_query_set(self, *args, **kwargs):
+ return superclass.get_query_set(self, *args, **kwargs).filter(**(self.core_filters))
def add(self, *objs):
for obj in objs:
@@ -398,7 +403,9 @@
manager.core_filters = {'%s__%s' % (rel_field.name, attname):
getattr(instance, attname)}
manager.model = self.related.model
-
+ manager.model_attname = rel_field.name
+ manager.related_model_instance = instance
+ manager.related_model_attname = rel_field.rel.related_name
return manager
def create_many_related_manager(superclass, through=False):
@@ -420,8 +427,8 @@
if self._pk_val is None:
raise ValueError("%r instance needs to have a primary key value before a many-to-many relationship can be used." % instance.__class__.__name__)
- def get_query_set(self):
- return superclass.get_query_set(self)._next_is_sticky().filter(**(self.core_filters))
+ def get_query_set(self, *args, **kwargs):
+ return superclass.get_query_set(self, *args, **kwargs)._next_is_sticky().filter(**(self.core_filters))
# If the ManyToMany relation has an intermediary model,
# the add and remove methods do not exist.
@@ -566,7 +573,9 @@
source_col_name=qn(self.related.field.m2m_reverse_name()),
target_col_name=qn(self.related.field.m2m_column_name())
)
-
+ manager.model_attname = self.related.field.name
+ manager.related_model_instance = instance
+ manager.related_model_attname = self.related.get_accessor_name()
return manager
def __set__(self, instance, value):
@@ -611,7 +620,9 @@
source_col_name=qn(self.field.m2m_column_name()),
target_col_name=qn(self.field.m2m_reverse_name())
)
-
+ manager.model_attname = self.field.related.get_accessor_name()
+ manager.related_model_instance = instance
+ manager.related_model_attname = self.field.attname
return manager
def __set__(self, instance, value):