Author: russellm
Date: 2010-04-02 10:44:48 -0500 (Fri, 02 Apr 2010)
New Revision: 12908

Modified:
   django/trunk/django/db/models/fields/related.py
   django/trunk/tests/regressiontests/m2m_regress/models.py
Log:
Fixed #11956 -- Modified the handling of m2m relationships between subclasses. 
Thanks to nidi for the report, and astoneman for the suggestion on how to fix 
the problem.

Modified: django/trunk/django/db/models/fields/related.py
===================================================================
--- django/trunk/django/db/models/fields/related.py     2010-04-02 14:44:16 UTC 
(rev 12907)
+++ django/trunk/django/db/models/fields/related.py     2010-04-02 15:44:48 UTC 
(rev 12908)
@@ -710,7 +710,7 @@
             model=rel_model,
             core_filters={'%s__pk' % self.field.related_query_name(): 
instance._get_pk_val()},
             instance=instance,
-            symmetrical=(self.field.rel.symmetrical and isinstance(instance, 
rel_model)),
+            symmetrical=self.field.rel.symmetrical,
             source_field_name=self.field.m2m_field_name(),
             target_field_name=self.field.m2m_reverse_field_name(),
             reverse=False
@@ -991,7 +991,7 @@
         kwargs['rel'] = ManyToManyRel(to,
             related_name=kwargs.pop('related_name', None),
             limit_choices_to=kwargs.pop('limit_choices_to', None),
-            symmetrical=kwargs.pop('symmetrical', True),
+            symmetrical=kwargs.pop('symmetrical', 
to==RECURSIVE_RELATIONSHIP_CONSTANT),
             through=kwargs.pop('through', None))
 
         self.db_table = kwargs.pop('db_table', None)

Modified: django/trunk/tests/regressiontests/m2m_regress/models.py
===================================================================
--- django/trunk/tests/regressiontests/m2m_regress/models.py    2010-04-02 
14:44:16 UTC (rev 12907)
+++ django/trunk/tests/regressiontests/m2m_regress/models.py    2010-04-02 
15:44:48 UTC (rev 12908)
@@ -17,6 +17,13 @@
     def __unicode__(self):
         return self.name
 
+# Regression for #11956 -- a many to many to the base class
+class TagCollection(Tag):
+    tags = models.ManyToManyField(Tag, related_name='tag_collections')
+
+    def __unicode__(self):
+        return self.name
+
 # A related_name is required on one of the ManyToManyField entries here because
 # they are both addressable as reverse relations from Tag.
 class Entry(models.Model):
@@ -102,5 +109,17 @@
 >>> w.save()
 >>> w.delete()
 
+# Regression for #11956 -- You can add an object to a m2m with the
+# base class without causing integrity errors
+>>> c1 = TagCollection.objects.create(name='c1')
+>>> c1.tags = [t1,t2]
+
+>>> c1 = TagCollection.objects.get(name='c1')
+>>> c1.tags.all()
+[<Tag: t1>, <Tag: t2>]
+
+>>> t1.tag_collections.all()
+[<TagCollection: c1>]
+
 """
 }

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to