Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace "this field is required" message in django admin

is there a way to replace the default error message in django admin. I'm using custom widget so I have the form and I was wondering is there something like:
field_1 = forms.Charfield(widget=X, error_messge='y')

I already tried to add claen_field_1 method but it looks that it is not called when the field is empty. Any ideas will be appreciated

like image 277
Ilian Iliev Avatar asked Aug 23 '10 10:08

Ilian Iliev


People also ask

How do you remove this field is required Django?

If yes try to disable this behavior, set the novalidate attribute on the form tag As <form action="{% url 'new_page' %}", method="POST" novalidate> in your html file.

How do you make a field mandatory in Django admin?

Making Fields Required In Django Admin In order to make the summary field required, we need to create a custom form for the Post model. I am making them on the same file you can do this on a separate forms.py file as well.

How do you make a field non mandatory in Django admin?

The simplest way is by using the field option blank=True (docs.djangoproject.com/en/dev/ref/models/fields/#blank).

How can we make field required in Django?

Let's try to use required via Django Web application we created, visit http://localhost:8000/ and try to input the value based on option or validation applied on the Field. Hit submit. Hence Field is accepting the form even without any data in the geeks_field. This makes required=False implemented successfully.


1 Answers

yes there is and actually this is forms functionality and not admin functionality ;), you can use this anywhere.

field_1 = forms.Charfield(widget=X, error_messages={'required': 'y'})

for more information see the django docs

like image 88
KillianDS Avatar answered Nov 14 '22 21:11

KillianDS