mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-17 03:51:03 +03:00
Merge pull request #3045 from paxnovem/issue_3042
Fixed many=False issue on related fields
This commit is contained in:
commit
15a386e85d
|
@ -42,6 +42,7 @@ class RelatedField(Field):
|
||||||
'Relational fields should not provide a `queryset` argument, '
|
'Relational fields should not provide a `queryset` argument, '
|
||||||
'when setting read_only=`True`.'
|
'when setting read_only=`True`.'
|
||||||
)
|
)
|
||||||
|
kwargs.pop('many', None)
|
||||||
super(RelatedField, self).__init__(**kwargs)
|
super(RelatedField, self).__init__(**kwargs)
|
||||||
|
|
||||||
def __new__(cls, *args, **kwargs):
|
def __new__(cls, *args, **kwargs):
|
||||||
|
|
|
@ -48,6 +48,11 @@ class TestPrimaryKeyRelatedField(APISimpleTestCase):
|
||||||
representation = self.field.to_representation(self.instance)
|
representation = self.field.to_representation(self.instance)
|
||||||
assert representation == self.instance.pk
|
assert representation == self.instance.pk
|
||||||
|
|
||||||
|
def test_explicit_many_false(self):
|
||||||
|
field = serializers.PrimaryKeyRelatedField(queryset=self.queryset, many=False)
|
||||||
|
instance = field.to_internal_value(self.instance.pk)
|
||||||
|
assert instance is self.instance
|
||||||
|
|
||||||
|
|
||||||
class TestProxiedPrimaryKeyRelatedField(APISimpleTestCase):
|
class TestProxiedPrimaryKeyRelatedField(APISimpleTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user