mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-02 11:30:12 +03:00
Improvements according to review comments.
This commit is contained in:
parent
98a12e2d42
commit
b88e0dcbe5
|
@ -937,15 +937,14 @@ class ModelSerializer(Serializer):
|
||||||
many_to_many[field_name] = validated_data.pop(field_name)
|
many_to_many[field_name] = validated_data.pop(field_name)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
instance = ModelClass(**validated_data)
|
instance = ModelClass._default_manager.create(**validated_data)
|
||||||
instance.save(force_insert=True)
|
|
||||||
except TypeError:
|
except TypeError:
|
||||||
tb = traceback.format_exc()
|
tb = traceback.format_exc()
|
||||||
msg = (
|
msg = (
|
||||||
'Got a `TypeError` when calling `%s()`. '
|
'Got a `TypeError` when calling `%s._default_manager.create()`. '
|
||||||
'This may be because you have a writable field on the '
|
'This may be because you have a writable field on the '
|
||||||
'serializer class that is not a valid argument to '
|
'serializer class that is not a valid argument to '
|
||||||
'`%s()`. You may need to make the field '
|
'`%s._default_manager.create()`. You may need to make the field '
|
||||||
'read-only, or override the %s.create() method to handle '
|
'read-only, or override the %s.create() method to handle '
|
||||||
'this correctly.\nOriginal exception was:\n %s' %
|
'this correctly.\nOriginal exception was:\n %s' %
|
||||||
(
|
(
|
||||||
|
|
|
@ -133,7 +133,7 @@ class TestModelSerializer(TestCase):
|
||||||
})
|
})
|
||||||
serializer.is_valid()
|
serializer.is_valid()
|
||||||
|
|
||||||
msginitial = 'Got a `TypeError` when calling `OneFieldModel()`.'
|
msginitial = 'Got a `TypeError` when calling `OneFieldModel._default_manager.create()`.'
|
||||||
with self.assertRaisesMessage(TypeError, msginitial):
|
with self.assertRaisesMessage(TypeError, msginitial):
|
||||||
serializer.save()
|
serializer.save()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user