Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django ModelForm label captialisation

In my model I have;

title = models.CharField(verbose_name="eBay Listing Title",max_length=56)

Using a ModelForm the label shows as "EBay Listing Title" (capital E). I'm using

{{ field.label_tag }} 

on the form template (in a loop) to display the labels.

How can I get the label to show correctly with a lowercase first letter?

like image 582
zio Avatar asked Mar 07 '11 22:03

zio


2 Answers

You can override the label in the form

for example:

class YourForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        super(YourForm, self).__init__(*args, **kwargs)
        self.fields['title'].label = "eBay Listing Title"

    class Meta:
        model = YourModel
like image 102
dting Avatar answered Oct 22 '22 09:10

dting


Pass in the label argument http://docs.djangoproject.com/en/dev/ref/forms/fields/#label

The capitalization is just a default -- replacing underscores with spaces and capitalizing if you don't pass in anything.

Example from docs:

>>> class CommentForm(forms.Form):
...     name = forms.CharField(label='Your name')
like image 38
Yuji 'Tomita' Tomita Avatar answered Oct 22 '22 09:10

Yuji 'Tomita' Tomita