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
Prev Previous commit
Next Next commit
* many to many relationship do not have to_fields
  • Loading branch information
Harper04 committed Jan 19, 2015
commit 8263048af44bc1f3cf10ce740ee87e67b8a2a99a
7 changes: 5 additions & 2 deletions rest_framework/utils/model_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ def _get_forward_relationships(opts):
model_field=field,
related=_resolve_model(field.rel.to),
to_many=True,
# to_fields is an array but django lets you only set one to_field
to_field=field.to_fields[0] if len(field.to_fields) else None,
# manytomany do not have to_fields
to_field=None,
has_through_model=(
not field.rel.through._meta.auto_created
)
Expand All @@ -134,6 +134,7 @@ def _get_reverse_relationships(opts):
model_field=None,
related=relation.model,
to_many=relation.field.rel.multiple,
to_field=relation.field.to_fields[0] if len(relation.field.to_fields) else None,
has_through_model=False
)

Expand All @@ -144,6 +145,8 @@ def _get_reverse_relationships(opts):
model_field=None,
related=relation.model,
to_many=True,
# 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
Expand Down