Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Attempt to address Django 1.9 deprecate warnings related to field.rel
  • Loading branch information
jplock committed Feb 5, 2016
commit 004408a9e8621cfb283ada0d5d533a11c34a00d7
20 changes: 10 additions & 10 deletions rest_framework/utils/model_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,16 @@ def get_field_info(model):

def _get_pk(opts):
pk = opts.pk
while pk.rel and pk.rel.parent_link:
while pk.remote_field and pk.remote_field.parent_link:
# If model is a child via multi-table inheritance, use parent's pk.
pk = pk.rel.to._meta.pk
pk = pk.remote_field.to._meta.pk

return pk


def _get_fields(opts):
fields = OrderedDict()
for field in [field for field in opts.fields if field.serialize and not field.rel]:
for field in [field for field in opts.fields if field.serialize and not field.remote_field]:
fields[field.name] = field

return fields
Expand All @@ -104,10 +104,10 @@ def _get_forward_relationships(opts):
Returns an `OrderedDict` of field names to `RelationInfo`.
"""
forward_relations = OrderedDict()
for field in [field for field in opts.fields if field.serialize and field.rel]:
for field in [field for field in opts.fields if field.serialize and field.remote_field]:
forward_relations[field.name] = RelationInfo(
model_field=field,
related_model=_resolve_model(field.rel.to),
related_model=_resolve_model(field.remote_field.to),
to_many=False,
to_field=_get_to_field(field),
has_through_model=False
Expand All @@ -117,12 +117,12 @@ def _get_forward_relationships(opts):
for field in [field for field in opts.many_to_many if field.serialize]:
forward_relations[field.name] = RelationInfo(
model_field=field,
related_model=_resolve_model(field.rel.to),
related_model=_resolve_model(field.remote_field.to),
to_many=True,
# manytomany do not have to_fields
to_field=None,
has_through_model=(
not field.rel.through._meta.auto_created
not field.remote_field.through._meta.auto_created
)
)

Expand All @@ -144,7 +144,7 @@ def _get_reverse_relationships(opts):
reverse_relations[accessor_name] = RelationInfo(
model_field=None,
related_model=related,
to_many=relation.field.rel.multiple,
to_many=relation.field.remote_field.multiple,
to_field=_get_to_field(relation.field),
has_through_model=False
)
Expand All @@ -160,8 +160,8 @@ def _get_reverse_relationships(opts):
# manytomany do not have to_fields
to_field=None,
has_through_model=(
(getattr(relation.field.rel, 'through', None) is not None) and
not relation.field.rel.through._meta.auto_created
(getattr(relation.field.remote_field, 'through', None) is not None) and
not relation.field.remote_field.through._meta.auto_created
)
)

Expand Down