Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #10237 -- Corrected the handling of self-referential m2m fields…

… when using multi-table inheritance. Thanks to Justin Lilly for the report and patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10550 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 0fec0a5d704d487755209115719ca173913a43b7 1 parent ffd7b17
Russell Keith-Magee authored April 13, 2009
2  django/db/models/fields/related.py
@@ -582,7 +582,7 @@ def __get__(self, instance, instance_type=None):
22  tests/regressiontests/m2m_regress/models.py
@@ -26,6 +26,13 @@ class Entry(models.Model):
26 26
     def __unicode__(self):
27 27
         return self.name
28 28
 
  29
+# Two models both inheriting from a base model with a self-referential m2m field
  30
+class SelfReferChild(SelfRefer):
  31
+    pass
  32
+
  33
+class SelfReferChildSibling(SelfRefer):
  34
+    pass
  35
+
29 36
 __test__ = {"regressions": """
30 37
 # Multiple m2m references to the same model or a different model must be
31 38
 # distinguished when accessing the relations through an instance attribute.
@@ -57,7 +64,20 @@ def __unicode__(self):
57 64
 >>> SelfRefer.objects.filter(porcupine='fred')
58 65
 Traceback (most recent call last):
59 66
 ...
60  
-FieldError: Cannot resolve keyword 'porcupine' into field. Choices are: id, name, references, related
  67
+FieldError: Cannot resolve keyword 'porcupine' into field. Choices are: id, name, references, related, selfreferchild, selfreferchildsibling
  68
+
  69
+# Test to ensure that the relationship between two inherited models
  70
+# with a self-referential m2m field maintains symmetry
  71
+>>> sr_child = SelfReferChild(name="Hanna")
  72
+>>> sr_child.save()
  73
+
  74
+>>> sr_sibling = SelfReferChildSibling(name="Beth")
  75
+>>> sr_sibling.save()
  76
+>>> sr_child.related.add(sr_sibling)
  77
+>>> sr_child.related.all()
  78
+[<SelfRefer: Beth>]
  79
+>>> sr_sibling.related.all()
  80
+[<SelfRefer: Hanna>]
61 81
 
62 82
 """
63 83
 }

0 notes on commit 0fec0a5

Please sign in to comment.
Something went wrong with that request. Please try again.