diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py index 40d768975..1fea13802 100644 --- a/rest_framework/serializers.py +++ b/rest_framework/serializers.py @@ -410,10 +410,12 @@ class ModelSerializer(Serializer): info = model_meta.get_field_info(self.opts.model) ret = SortedDict() + # URL field serializer_url_field = self.get_url_field() if serializer_url_field: ret[api_settings.URL_FIELD_NAME] = serializer_url_field + # Primary key field field_name = info.pk.name serializer_pk_field = self.get_pk_field(field_name, info.pk) if serializer_pk_field: diff --git a/tests/test_model_field_mappings.py b/tests/test_model_field_mappings.py index 957bf6613..bae63e5a7 100644 --- a/tests/test_model_field_mappings.py +++ b/tests/test_model_field_mappings.py @@ -14,7 +14,7 @@ def dedent(blocktext): return '\n'.join([line[12:] for line in blocktext.splitlines()[1:-1]]) -# Models for testing regular field mapping +# Testing regular field mappings class RegularFieldsModel(models.Model): auto_field = models.AutoField(primary_key=True) @@ -70,7 +70,7 @@ class TestRegularFieldMappings(TestCase): self.assertEqual(repr(TestSerializer()), expected) -# Model for testing relational field mapping +# Testing relational field mappings class ForeignKeyTargetModel(models.Model): name = models.CharField(max_length=100)