Fixed #3906 -- Fixed the reverse_m2m_name for a generic relation. Refs #2749.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@6900 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick 2007-12-09 07:12:07 +00:00
parent 25f548a852
commit 5ed205bc8a
2 changed files with 38 additions and 34 deletions

View File

@ -118,7 +118,7 @@ class GenericRelation(RelatedField, Field):
return self.object_id_field_name return self.object_id_field_name
def m2m_reverse_name(self): def m2m_reverse_name(self):
return self.object_id_field_name return self.model._meta.pk.column
def contribute_to_class(self, cls, name): def contribute_to_class(self, cls, name):
super(GenericRelation, self).contribute_to_class(cls, name) super(GenericRelation, self).contribute_to_class(cls, name)

View File

@ -132,4 +132,8 @@ __test__ = {'API_TESTS':"""
>>> [(t.tag, t.content_type, t.object_id) for t in TaggedItem.objects.all()] >>> [(t.tag, t.content_type, t.object_id) for t in TaggedItem.objects.all()]
[(u'clearish', <ContentType: mineral>, 1), (u'salty', <ContentType: vegetable>, 2), (u'shiny', <ContentType: animal>, 2)] [(u'clearish', <ContentType: mineral>, 1), (u'salty', <ContentType: vegetable>, 2), (u'shiny', <ContentType: animal>, 2)]
>>> ctype = ContentType.objects.get_for_model(lion)
>>> Animal.objects.filter(tags__content_type=ctype)
[<Animal: Platypus>]
"""} """}