Code

Ticket #11226: m2m_name_clashes.diff

File m2m_name_clashes.diff, 1.4 KB (added by pkoch, 5 years ago)

Sugested solution

Line 
1Index: django/db/models/fields/related.py
2===================================================================
3--- django/db/models/fields/related.py  (revision 10858)
4+++ django/db/models/fields/related.py  (working copy)
5@@ -816,7 +816,7 @@
6                         self._m2m_column_name_cache = f.column
7                         break
8             # If this is an m2m relation to self, avoid the inevitable name clash
9-            elif related.model == related.parent_model:
10+            elif related.model._meta.object_name == related.parent_model._meta.object_name:
11                 self._m2m_column_name_cache = 'from_' + related.model._meta.object_name.lower() + '_id'
12             else:
13                 self._m2m_column_name_cache = related.model._meta.object_name.lower() + '_id'
14@@ -847,7 +847,7 @@
15                             self._m2m_reverse_name_cache = f.column
16                             break
17             # If this is an m2m relation to self, avoid the inevitable name clash
18-            elif related.model == related.parent_model:
19+            elif related.model._meta.object_name == related.parent_model._meta.object_name:
20                 self._m2m_reverse_name_cache = 'to_' + related.parent_model._meta.object_name.lower() + '_id'
21             else:
22                 self._m2m_reverse_name_cache = related.parent_model._meta.object_name.lower() + '_id'