Django Tutorials
Fields Validation

Fields Validation

If you want to validate a field using custom logic, you can override the clean method in the model class.

superapp/apps/<app_name>/models.py
from django.core.exceptions import ValidationError
from django_superapp.helpers import BaseModel
from django.db import models
 
class SampleModel(BaseModel):
    username = models.CharField(max_length=100)
 
    def clean(self):
        if len(self.username) <= 3:
            raise ValidationError("Username must be longer than 3 characters.")

Useful Resources