[Django]-Django rest api validate data sent in the requests

6👍

In your serializer class add a method to validate UnitOfMeasureName like following:

def validate_unitofmasurename(self, value):
    UnitOfMeasureName = ["Each", "Grams", "Ounces", "Pounds", "Kilograms", "Metric Tons"]
    if value in UnitOfMeasureName:
        return True
    else:
        return ValidationError('Invalid masure name')

Leave a comment