When you add a form field like that, it removes inheritance of field 
attributes like verbose_name from the model.

Instead, you could override Form.__init__() and set the widget similar to 
what's described at 
https://docs.djangoproject.com/en/stable/ref/forms/widgets/ "Or if the 
field isn’t declared directly on the form..."

I think it would be: self.fields['who'].widget = forms.Textarea()

On Friday, February 1, 2019 at 5:08:48 PM UTC-5, Michael Corey wrote:
>
> 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 [email protected].
To post to this group, send email to [email protected].
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/7f2a8cbc-6707-47ac-ab1c-fae34c599b77%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to