Created
December 10, 2019 05:51
-
-
Save aballah-chamakh/6b5cb34ea74f224fed121629025b82c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rest-framework import serializers | |
from .models import Review | |
class ReviewSerializer(serializers.Serializer): | |
class Meta : | |
model = Review | |
fields = ['username','content'] | |
# to validate any field override the function validate_<field> | |
def validate_username(self,value): | |
if len(value) > 20 : | |
raise serializers.ValidationError("the length of your username should be less than 20 character") | |
return value | |
# to validate on the serializer level | |
def validate(self, data): | |
if data['username'] == data['content'] : | |
raise serializers.ValidationError("the content value should not be the same as the username value ") | |
return value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment