mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-05 04:50:12 +03:00
Merge c77632babb
into 26623436f3
This commit is contained in:
commit
aba7cd7cca
|
@ -237,7 +237,12 @@ The one difference that you do need to note is that the `.clean()` method will n
|
||||||
There may be some cases where you really do need to keep validation logic in the model `.clean()` method, and cannot instead separate it into the serializer `.validate()`. You can do so by explicitly instantiating a model instance in the `.validate()` method.
|
There may be some cases where you really do need to keep validation logic in the model `.clean()` method, and cannot instead separate it into the serializer `.validate()`. You can do so by explicitly instantiating a model instance in the `.validate()` method.
|
||||||
|
|
||||||
def validate(self, attrs):
|
def validate(self, attrs):
|
||||||
instance = ExampleModel(**attrs)
|
if not self.instance:
|
||||||
|
instance = self.Meta.model(**attrs)
|
||||||
|
else:
|
||||||
|
instance = self.instance
|
||||||
|
for attr_name in attrs:
|
||||||
|
instance.attr_name = attrs.get('attr_name')
|
||||||
instance.clean()
|
instance.clean()
|
||||||
return attrs
|
return attrs
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user