Skip to content

Commit

Permalink
Fixed #11956 -- Modified the handling of m2m relationships between su…
Browse files Browse the repository at this point in the history
…bclasses. Thanks to nidi for the report, and astoneman for the suggestion on how to fix the problem.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12908 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
freakboy3742 committed Apr 2, 2010
1 parent 8f8743a commit 5e5203c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions django/db/models/fields/related.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ def __get__(self, instance, instance_type=None):
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
Expand Down Expand Up @@ -991,7 +991,7 @@ def __init__(self, to, **kwargs):
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)
Expand Down
19 changes: 19 additions & 0 deletions tests/regressiontests/m2m_regress/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ class Tag(models.Model):
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):
Expand Down Expand Up @@ -102,5 +109,17 @@ class User(models.Model):
>>> 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>]
"""
}

0 comments on commit 5e5203c

Please sign in to comment.