Hello good Django people!
I am reading the docs but it is a bit confusing. I don’t understand where and which error messages are being applied.
Example:
I have a Course model with a title field.
# COURSE MODEL
class Course(models.Model):
class Level(models.TextChoices):
BEGINNER = 'BEGINNER', 'Beginner'
INTERMEDIATE = 'INTERMEDIATE', 'Intermediate'
ADVANCED = 'ADVANCED', 'Advanced'
title = models.CharField(max_length=150, unique=True,
error_messages ={
"unique":"Kurs sa ovim imenom vec postoji."
})
slug = models.SlugField(max_length=160, unique=True,
error_messages ={
'unique':'Kurs sa ovom url adresom vec postoji.',
'slug_invalid':'Unesite ipravnu url adresu, dozvoljeni su brojevi, slova, donje crte i minus crte.',
})
This is the template
{{ form.title.label_tag }}
{{ form.title }}
{% for error in form.title.errors %}
<p class="error">{{ error }}</p>
{% endfor %}
</div>
<hr>
{{ form.slug.label_tag }}
{{ form.slug }}
{% for error in form.slug.errors %}
<p class="error">{{ error }}</p>
{% endfor %}
<hr>
But for the slug field, if entered characters are not okay, i still get the default:
“Enter a valid “slug” consisting of letters, numbers, underscores or hyphens.”
I also tried the key ‘invalid’ but it is not showing up.
Can somebody please explain where and how i can change the text for error messages for model fields? Basically all i want is to translate them into Serbian.
Thank you