aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework
diff options
context:
space:
mode:
authorTom Christie2015-01-23 11:15:11 +0000
committerTom Christie2015-01-23 11:15:11 +0000
commit25a703b42c030f712734ed56b8f1996f8d13ac0c (patch)
tree987467eff66dd0383d1f60eaaa468d963df0d5b7 /rest_framework
parente56f0a928c7ec6af15a283fc48a7dded31a7d113 (diff)
downloaddjango-rest-framework-25a703b42c030f712734ed56b8f1996f8d13ac0c.tar.bz2
Work around meta API differences
Diffstat (limited to 'rest_framework')
-rw-r--r--rest_framework/utils/model_meta.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/rest_framework/utils/model_meta.py b/rest_framework/utils/model_meta.py
index 375d2e8c..6a5835f5 100644
--- a/rest_framework/utils/model_meta.py
+++ b/rest_framework/utils/model_meta.py
@@ -121,12 +121,17 @@ def _get_reverse_relationships(opts):
"""
Returns an `OrderedDict` of field names to `RelationInfo`.
"""
+ # Note that we have a hack here to handle internal API differences for
+ # this internal API across Django 1.7 -> Django 1.8.
+ # See: https://code.djangoproject.com/ticket/24208
+
reverse_relations = OrderedDict()
for relation in opts.get_all_related_objects():
accessor_name = relation.get_accessor_name()
+ related = getattr(relation, 'related_model', relation.model)
reverse_relations[accessor_name] = RelationInfo(
model_field=None,
- related=relation.model,
+ related=related,
to_many=relation.field.rel.multiple,
has_through_model=False
)
@@ -134,9 +139,10 @@ def _get_reverse_relationships(opts):
# Deal with reverse many-to-many relationships.
for relation in opts.get_all_related_many_to_many_objects():
accessor_name = relation.get_accessor_name()
+ related = getattr(relation, 'related_model', relation.model)
reverse_relations[accessor_name] = RelationInfo(
model_field=None,
- related=relation.model,
+ related=related,
to_many=True,
has_through_model=(
(getattr(relation.field.rel, 'through', None) is not None)