Skip to content

Conversation

@mojtabaakbari221b
Copy link

@mojtabaakbari221b mojtabaakbari221b commented Jan 3, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant