Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add is_valid logic to base model #173

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

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