Hello, i'm using custom class validator to validate serializer fields, and i would like to raise ValidationError for all fields, instead now i'm getting the validation error only for single fields. Before i've used method validations inside my serialzier and it worked as i need, but this is nto the case with class validators.
class TitleValidator:
MIN_TITLE_LENGTH = 20
def __call__(self, attrs: dict):
title = attrs.get("title", "")
if len(title) < self.MIN_TITLE_LENGTH:
raise ValidationError(f"Min title length is {self.MIN_TITLE_LENGTH}")
return title
class SlugsValidator:
def __call__(self, attrs):
slug = attrs.get("slug", "")
if len(slug) < 10:
raise ValidationError("Slug must be at least 10 characters long")
return slug
Inside my serializer i'm using validators inside Meta class.