I'm having trouble getting the verbose_name attribute of a model field to 
show up when rendering a ModelForm. instead, the label uses the pretty 
version of the field name, not the verbose_name. This occurs any time I 
specify a field type, and works properly (shows the verbose_name) if I 
don't specify a field type.

Version 1: This works (i.e. it shows the verbose name as the label)...
```
# models.py

class Pitch(models.Model):
    dummy = models.CharField(verbose_name="not a real field just so I can 
exclude something for this bug report")
    who = models.TextField(max_length=3000, verbose_name="In a few lines, 
tell us what your story is about and what question your story is trying to 
answer.")


# forms.py
class PitchForm(forms.ModelForm):
    class Meta:
        model = Pitch
        excludes = ['dummy']

# pitchform.html

 {% for field in form %}
      {{ field.label }}
      <div class="fieldWrapper">
          {{ field.errors }}
          {{ field.label_tag }} {{ field }}
          {% if field.help_text %}
          <p class="help">{{ field.help_text|safe }}</p>
          {% endif %}
      </div>
      {% endif %}
 {% endfor %}

```

Version 2: This does not work (shows a prettified version of the field 
name, not the verbose_name). The only difference is specifying a CharField 
in forms.py
```
# models.py

class Pitch(models.Model):
    dummy = models.CharField(verbose_name="not a real field just so I can 
exclude something for this bug report")
    who = models.TextField(max_length=3000, verbose_name="In a few lines, 
tell us what your story is about and what question your story is trying to 
answer.")


# forms.py
class PitchForm(forms.ModelForm):
    who = forms.CharField(widget=forms.Textarea)
    
    class Meta:
        model = Pitch
        excludes = ['dummy']

# pitchform.html

 {% for field in form %}
      {{ field.label }}
      <div class="fieldWrapper">
          {{ field.errors }}
          {{ field.label_tag }} {{ field }}
          {% if field.help_text %}
          <p class="help">{{ field.help_text|safe }}</p>
          {% endif %}
      </div>
      {% endif %}
 {% endfor %}

```

Am I doing it wrong?

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/643a1fbb-5b20-4669-b370-cc83f708570e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to