mirror of https://github.com/django/django.git
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
This commit is contained in:
parent
ffd7b177c9
commit
0fec0a5d70
|
@ -582,7 +582,7 @@ class ReverseManyRelatedObjectsDescriptor(object):
|
|||
model=rel_model,
|
||||
core_filters={'%s__pk' % self.field.related_query_name(): instance._get_pk_val()},
|
||||
instance=instance,
|
||||
symmetrical=(self.field.rel.symmetrical and instance.__class__ == rel_model),
|
||||
symmetrical=(self.field.rel.symmetrical and isinstance(instance, rel_model)),
|
||||
join_table=qn(self.field.m2m_db_table()),
|
||||
source_col_name=qn(self.field.m2m_column_name()),
|
||||
target_col_name=qn(self.field.m2m_reverse_name())
|
||||
|
|
|
@ -26,6 +26,13 @@ class Entry(models.Model):
|
|||
def __unicode__(self):
|
||||
return self.name
|
||||
|
||||
# Two models both inheriting from a base model with a self-referential m2m field
|
||||
class SelfReferChild(SelfRefer):
|
||||
pass
|
||||
|
||||
class SelfReferChildSibling(SelfRefer):
|
||||
pass
|
||||
|
||||
__test__ = {"regressions": """
|
||||
# Multiple m2m references to the same model or a different model must be
|
||||
# distinguished when accessing the relations through an instance attribute.
|
||||
|
@ -57,7 +64,20 @@ __test__ = {"regressions": """
|
|||
>>> SelfRefer.objects.filter(porcupine='fred')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
FieldError: Cannot resolve keyword 'porcupine' into field. Choices are: id, name, references, related
|
||||
FieldError: Cannot resolve keyword 'porcupine' into field. Choices are: id, name, references, related, selfreferchild, selfreferchildsibling
|
||||
|
||||
# Test to ensure that the relationship between two inherited models
|
||||
# with a self-referential m2m field maintains symmetry
|
||||
>>> sr_child = SelfReferChild(name="Hanna")
|
||||
>>> sr_child.save()
|
||||
|
||||
>>> sr_sibling = SelfReferChildSibling(name="Beth")
|
||||
>>> sr_sibling.save()
|
||||
>>> sr_child.related.add(sr_sibling)
|
||||
>>> sr_child.related.all()
|
||||
[<SelfRefer: Beth>]
|
||||
>>> sr_sibling.related.all()
|
||||
[<SelfRefer: Hanna>]
|
||||
|
||||
"""
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue