diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py index 329b38f2d..46d4765e1 100644 --- a/rest_framework/serializers.py +++ b/rest_framework/serializers.py @@ -388,7 +388,10 @@ class ModelSerializer(Serializer): """ Creates a default instance of a nested relational field. """ - return ModelSerializer() + class NestedModelSerializer(ModelSerializer): + class Meta: + model = model_field.rel.to + return NestedModelSerializer() def get_related_field(self, model_field, to_many=False): """ diff --git a/rest_framework/tests/pk_relations.py b/rest_framework/tests/pk_relations.py index 44ae40409..3dcc76f97 100644 --- a/rest_framework/tests/pk_relations.py +++ b/rest_framework/tests/pk_relations.py @@ -136,6 +136,7 @@ class PrimaryKeyManyToManyTests(TestCase): ] self.assertEquals(serializer.data, expected) + class PrimaryKeyForeignKeyTests(TestCase): def setUp(self): target = ForeignKeyTarget(name='target-1')