Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add verbose_name to forms

Tags:

django

How to add verbose_name to forms in Django?

In forms.py:

class SendOrderForm(forms.Form):    send_option = forms.ModelChoiceField(queryset=Send.objects.all(), verbose_name="Send Options") 

This is not correct

like image 653
sagem_tetra Avatar asked Nov 06 '12 09:11

sagem_tetra


People also ask

How do you create a model form?

First, create a model that contains fields name and other metadata. It can be used to create a table in database and dynamic HTML form. This file contains a class that inherits ModelForm and mention the model name for which HTML form is created. Write a view function to load the ModelForm from forms.py.

How do you exclude a specific field from a ModelForm?

Set the exclude attribute of the ModelForm 's inner Meta class to a list of fields to be excluded from the form.

What is the use of Verbose_name in Django model?

verbose_name is a human-readable name for the field. If the verbose name isn't given, Django will automatically create it using the field's attribute name, converting underscores to spaces. This attribute in general changes the field name in admin interface.


1 Answers

I think, label argument is what you need:

class SendOrderForm(forms.Form):    send_option = forms.ModelChoiceField(queryset=Send.objects.all(), label="Send Options") 
like image 198
Serhii Holinei Avatar answered Sep 27 '22 20:09

Serhii Holinei