1
0
mirror of https://github.com/django/django.git synced 2025-07-04 17:59:13 +00:00

[1.1.X] 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.

Backport of r12908 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12909 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Russell Keith-Magee 2010-04-02 15:52:58 +00:00
parent adfeb96227
commit ac0aea8910
2 changed files with 21 additions and 2 deletions

View File

@ -606,7 +606,7 @@ class ReverseManyRelatedObjectsDescriptor(object):
model=rel_model, model=rel_model,
core_filters={'%s__pk' % self.field.related_query_name(): instance._get_pk_val()}, core_filters={'%s__pk' % self.field.related_query_name(): instance._get_pk_val()},
instance=instance, instance=instance,
symmetrical=(self.field.rel.symmetrical and isinstance(instance, rel_model)), symmetrical=self.field.rel.symmetrical,
join_table=qn(self.field.m2m_db_table()), join_table=qn(self.field.m2m_db_table()),
source_col_name=qn(self.field.m2m_column_name()), source_col_name=qn(self.field.m2m_column_name()),
target_col_name=qn(self.field.m2m_reverse_name()) target_col_name=qn(self.field.m2m_reverse_name())
@ -804,7 +804,7 @@ class ManyToManyField(RelatedField, Field):
kwargs['rel'] = ManyToManyRel(to, kwargs['rel'] = ManyToManyRel(to,
related_name=kwargs.pop('related_name', None), related_name=kwargs.pop('related_name', None),
limit_choices_to=kwargs.pop('limit_choices_to', 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)) through=kwargs.pop('through', None))
self.db_table = kwargs.pop('db_table', None) self.db_table = kwargs.pop('db_table', None)

View File

@ -17,6 +17,13 @@ class Tag(models.Model):
def __unicode__(self): def __unicode__(self):
return self.name 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 # A related_name is required on one of the ManyToManyField entries here because
# they are both addressable as reverse relations from Tag. # they are both addressable as reverse relations from Tag.
class Entry(models.Model): class Entry(models.Model):
@ -102,5 +109,17 @@ FieldError: Cannot resolve keyword 'porcupine' into field. Choices are: id, name
>>> w.save() >>> w.save()
>>> w.delete() >>> 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>]
""" """
} }