summaryrefslogtreecommitdiff
path: root/django/db/models/fields
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2012-10-02 22:52:45 +0800
committerRussell Keith-Magee <russell@keith-magee.com>2012-10-02 22:52:45 +0800
commit3b6f980bedbbf091fe29bececa2b262d2084ce4d (patch)
tree79878a20a702edb034cd732c850ff5546059edf6 /django/db/models/fields
parent5f8b97f9fb058e5e02f1f99423fc3b0020ecdeb0 (diff)
Fixed #19049 -- Ensure that swapped models aren't included in reverse field caches.
Thanks to Ivan Virabyan for the report.
Diffstat (limited to 'django/db/models/fields')
-rw-r--r--django/db/models/fields/related.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py
index c065162aa0..2c35411d7c 100644
--- a/django/db/models/fields/related.py
+++ b/django/db/models/fields/related.py
@@ -1025,8 +1025,8 @@ class ForeignKey(RelatedField, Field):
def contribute_to_related_class(self, cls, related):
# Internal FK's - i.e., those with a related name ending with '+' -
- # don't get a related descriptor.
- if not self.rel.is_hidden():
+ # and swapped models don't get a related descriptor.
+ if not self.rel.is_hidden() and related.model._meta.swapped:
setattr(cls, related.get_accessor_name(), ForeignRelatedObjectsDescriptor(related))
if self.rel.limit_choices_to:
cls._meta.related_fkey_lookups.append(self.rel.limit_choices_to)
@@ -1265,8 +1265,8 @@ class ManyToManyField(RelatedField, Field):
def contribute_to_related_class(self, cls, related):
# Internal M2Ms (i.e., those with a related name ending with '+')
- # don't get a related descriptor.
- if not self.rel.is_hidden():
+ # and swapped models don't get a related descriptor.
+ if not self.rel.is_hidden() and not related.model._meta.swapped:
setattr(cls, related.get_accessor_name(), ManyRelatedObjectsDescriptor(related))
# Set up the accessors for the column names on the m2m table