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
…ramework

Conflicts:
	rest_framework/serializers.py
  • Loading branch information
Harper04 committed Apr 16, 2015
commit 8096997f25a135b1b2cec9974d88ebbc8184cc58
32 changes: 7 additions & 25 deletions rest_framework/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,9 +730,12 @@ class ModelSerializer(Serializer):
models.TextField: CharField,
models.TimeField: TimeField,
models.URLField: URLField,
})
_related_class = PrimaryKeyRelatedField
_related_to_field_class = SlugRelatedField
}
serializer_related_field = PrimaryKeyRelatedField
serializer_url_field = HyperlinkedIdentityField
serializer_choice_field = ChoiceField

# Default `create` and `update` behavior...

def create(self, validated_data):
"""
Expand Down Expand Up @@ -1249,28 +1252,7 @@ def _get_model_fields(self, field_names, declared_fields, extra_kwargs):
except FieldDoesNotExist:
pass

elif field_name in info.relations:
# Create forward and reverse relationships.
relation_info = info.relations[field_name]
if depth:
field_cls = self._get_nested_class(depth, relation_info)
kwargs = get_nested_relation_kwargs(relation_info)
else:
kwargs = get_relation_kwargs(field_name, relation_info)
to_field = kwargs.get('to_field', False)
kwargs.pop('to_field', None)
# it seems that some tests/django initializers are setting
# to_field where it is totally unnecessary
if to_field and to_field != 'id':
# using the slug field for now
kwargs.pop('to_field', None)
kwargs['slug_field'] = to_field
field_cls = self._related_to_field_class
else:
field_cls = self._related_class
# `view_name` is only valid for hyperlinked relationships.
if not issubclass(field_cls, HyperlinkedRelatedField):
kwargs.pop('view_name', None)
return model_fields

# Determine the validators to apply...

Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.