doniyor
doniyor

Reputation: 37876

django user model - override labels in model form

I am trying to override the field labels of django's user model

i did:

class UserForm(ModelForm):
  class Meta:
    model = User
    fields = ["first_name", "last_name","username", "email", "password"]
    labels = {
        'first_name': 'Vorname',
        'last_name': 'Nachname',
    }

and in template

{{uform}}

i am getting still First Name, Last Name instead of Vorname and Nachname. am I missing something?

Upvotes: 1

Views: 412

Answers (1)

Leistungsabfall
Leistungsabfall

Reputation: 6488

The way you are doing it only works with Django 1.6 or newer.

With older Django installations you will have to do it this way:

class UserForm(ModelForm):
    first_name = forms.CharField(label='Vorname')
    # ...

    class Meta:
        model = User
        fields = ["first_name", "last_name", "username", "email", "password"]

Upvotes: 3

Related Questions