Suppose you want to validate a schema, in the current state, you should call the validate function and see if it is none, that means the data is valid.
The first problem is that we don't have a clean code of true or false, and the second is that we don't have a list of fields that are invalid, and we only know about 1 field being invalid.
The second problem: suppose we want to return a list of invalid fields to the user, how?
This is how you can do these things with the new codes :
And imagine that we use drf in our api development.
from rest_framework.response import Response
person = Person(name='Chuck', surname='Norris')
if person.is_valid()
return Reponse(status=201)
else:
return Response(data=person.errors, status=401)
In general, this implementation is inspired by the implementation of isـvalid in drf serializer
Suppose you want to validate a schema, in the current state, you should call the validate function and see if it is none, that means the data is valid. The first problem is that we don't have a clean code of true or false, and the second is that we don't have a list of fields that are invalid, and we only know about 1 field being invalid. The second problem: suppose we want to return a list of invalid fields to the user, how?
This is how you can do these things with the new codes : And imagine that we use drf in our api development.
In general, this implementation is inspired by the implementation of isـvalid in drf serializer