mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-26 11:33:59 +03:00
Merge pull request #2196 from tomchristie/tomchristie-improve-update-nested-validation
Improve checks for nested creates and updates.
This commit is contained in:
commit
66bce38b59
|
@ -633,8 +633,8 @@ class ModelSerializer(Serializer):
|
|||
# If we don't do this explicitly they'd likely get a confusing
|
||||
# error at the point of calling `Model.objects.create()`.
|
||||
assert not any(
|
||||
isinstance(field, BaseSerializer) and not field.read_only
|
||||
for field in self.fields.values()
|
||||
isinstance(field, BaseSerializer) and (key in validated_attrs)
|
||||
for key, field in self.fields.items()
|
||||
), (
|
||||
'The `.create()` method does not suport nested writable fields '
|
||||
'by default. Write an explicit `.create()` method for serializer '
|
||||
|
@ -681,8 +681,8 @@ class ModelSerializer(Serializer):
|
|||
|
||||
def update(self, instance, validated_attrs):
|
||||
assert not any(
|
||||
isinstance(field, BaseSerializer) and not field.read_only
|
||||
for field in self.fields.values()
|
||||
isinstance(field, BaseSerializer) and (key in validated_attrs)
|
||||
for key, field in self.fields.items()
|
||||
), (
|
||||
'The `.update()` method does not suport nested writable fields '
|
||||
'by default. Write an explicit `.update()` method for serializer '
|
||||
|
|
Loading…
Reference in New Issue
Block a user