Note that there are some explanatory texts on larger screens.

plurals
  1. POdjango verbose_name not working
    primarykey
    data
    text
    <p>So I have a model called Users and it has a field called first_name.</p> <pre><code>class Users(models.Model): alpha_field = RegexValidator(regex=r'^[a-zA-Z]+$', message='Name can only contain letters') user_id = models.AutoField(unique=True, primary_key=True) username = models.SlugField(max_length=50, unique=True) first_name = models.CharField(max_length=50, verbose_name='first Name', validators=[alpha_field]) last_name = models.CharField(max_length=50, validators=[alpha_field]) password = models.SlugField(max_length=50) </code></pre> <p>and then I created a UsersForm and then in my template page, when displaying any error messages, it doesn't use the verbose name, it uses first_name. For example, my template code for display errors is</p> <pre><code>{% for field, error in form.errors.items %} {% if forloop.counter == 1 %} {{ field }}{{ error | striptags }} {% endif %} {% endfor %} </code></pre> <p>If there is an error in the first_name field, like if I didn't fill it out and still clicked submit, it would display this</p> <p>"first_nameThis field is required" How do I make it display "First NameThis field is required" instead?</p> <p>Not that it might make a different but do note that I am using south and schemamigration to update the database, it originally did not have a verbose name but I recently added it and then just saved the file (I didn't do a schemamigration and then migrate the app because it said that no changes seem to have been made). </p> <p>My UsersForm is this:</p> <pre><code>from django import forms from models import Users class UsersForm(forms.ModelForm): class Meta: model = Users widgets = {'password':forms.PasswordInput()} def __init__(self, *args, **kwargs): super( UsersForm, self ).__init__(*args, **kwargs) self.fields[ 'username' ].widget.attrs[ 'placeholder' ]="Username" self.fields[ 'first_name' ].widget.attrs[ 'placeholder' ]="First Name" self.fields[ 'last_name' ].widget.attrs[ 'placeholder' ]="Last Name" self.fields[ 'password' ].widget.attrs[ 'placeholder' ]="Password" self.fields['first_name'].label='first Name' </code></pre> <p>my view is here:</p> <pre><code>def home_page(request): form = UsersForm() if request.method == "POST": form = UsersForm(request.POST) if form.is_valid(): form.save() c = {} c.update(csrf(request)) c.update({'form':form}) return render_to_response('home_page.html', c) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload