Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

magic-removal: Refs #1346 -- Added the production of 'mirror' entries…

… in the m2m table for m2m relations to self.

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2382 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 4f6d2a1d088ae724d4261cefcd1bc273d95ab573 1 parent 492d214
@freakboy3742 freakboy3742 authored
Showing with 17 additions and 0 deletions.
  1. +17 −0 django/db/models/fields/related.py
View
17 django/db/models/fields/related.py
@@ -300,15 +300,32 @@ def get_query_set(self):
def add(self, *objs, **kwargs):
_add_m2m_items(self, superclass, rel_model, join_table, source_col_name,
target_col_name, instance._get_pk_val(), *objs, **kwargs)
+
+ # If this is an m2m relation to self, add the mirror entry in the m2m table
+ if instance.__class__ == rel_model:
+ _add_m2m_items(self, superclass, rel_model, join_table, target_col_name,
+ source_col_name, instance._get_pk_val(), *objs, **kwargs)
+
add.alters_data = True
def remove(self, *objs):
_remove_m2m_items(rel_model, join_table, source_col_name,
target_col_name, instance._get_pk_val(), *objs)
+
+ # If this is an m2m relation to self, remove the mirror entry in the m2m table
+ if instance.__class__ == rel_model:
+ _remove_m2m_items(rel_model, join_table, target_col_name,
+ source_col_name, instance._get_pk_val(), *objs)
+
remove.alters_data = True
def clear(self):
_clear_m2m_items(join_table, source_col_name, instance._get_pk_val())
+
+ # If this is an m2m relation to self, clear the mirror entry in the m2m table
+ if instance.__class__ == rel_model:
+ _clear_m2m_items(join_table, target_col_name, instance._get_pk_val())
+
clear.alters_data = True
manager = RelatedManager()
Please sign in to comment.
Something went wrong with that request. Please try again.