From bb2182453b49157fb6fba4de6d3c53a09f73d74b Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Sun, 29 Jun 2008 02:36:18 +0000 Subject: Fixed handling of multiple fields in a model pointing to the same related model. Thanks to ElliotM, mk and oyvind for some excellent test cases for this. Fixed #7110, #7125. git-svn-id: http://code.djangoproject.com/svn/django/trunk@7778 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/db/models/fields/related.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'django/db/models/fields') diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py index 9678ba4154..a8d402dcfd 100644 --- a/django/db/models/fields/related.py +++ b/django/db/models/fields/related.py @@ -692,6 +692,11 @@ class ForeignKey(RelatedField, Field): def contribute_to_class(self, cls, name): super(ForeignKey, self).contribute_to_class(cls, name) setattr(cls, self.name, ReverseSingleRelatedObjectDescriptor(self)) + if isinstance(self.rel.to, basestring): + target = self.rel.to + else: + target = self.rel.to._meta.db_table + cls._meta.duplicate_targets[self.column] = (target, "o2m") def contribute_to_related_class(self, cls, related): setattr(cls, related.get_accessor_name(), ForeignRelatedObjectsDescriptor(related)) @@ -826,6 +831,12 @@ class ManyToManyField(RelatedField, Field): # Set up the accessor for the m2m table name for the relation self.m2m_db_table = curry(self._get_m2m_db_table, cls._meta) + if isinstance(self.rel.to, basestring): + target = self.rel.to + else: + target = self.rel.to._meta.db_table + cls._meta.duplicate_targets[self.column] = (target, "m2m") + def contribute_to_related_class(self, cls, related): # m2m relations to self do not have a ManyRelatedObjectsDescriptor, # as it would be redundant - unless the field is non-symmetrical. -- cgit v1.3