STAY INFORMED
following content serves as a personal note and may lack complete accuracy or certainty.

Minimal-Mistakes instruction
Useful vscode Shortcut Keys
Unix Commands
npm Commands
Vim Commands
Git Note
Useful Figma Shortcut Keys

less than 1 minute read

Validator

Use Internal django Validator

# models.py

from django.core.validators import MinLengthValidator

class Post(models.Model):

    content = models.TextField(validators=[MinLengthValidator(10, 'need at least 10 letters.')])

Create Validator Function

# validators.py

from django.core.exceptions import ValidationError

def validateSymbols(value):
    if ('&' in value):
        raise ValidationError('"&" cannot be included')

and need to apply this function in models.py

from .validators import validateSymbols

class Post(models.Model):
    content = models.TextField(validators=[MinLengthValidator(10, 'need at least 10 letters.'), validateSymbols])

Use Validator at Form

from django.core.exceptions import ValidationError

class PostForm(forms.ModelForm):

    class Meta:
        model = Post
        fields = '__all__'
        widgets = {'title': forms.TextInput(attrs={
            'class': 'title',
            'placeholder': 'this is placeholder'}),
            'content': forms.Textarea(attrs={'placeholder': 'need content'})}
    
    def clean_title(self):
        title = self.cleaned_data['title']
        if '*' in title:
            raise ValidationError('* cannot be included')
        return title

des1

more info about django validator