I want to display name in front of field instead of

10,350

You need to use verbose_name instead of name in your model.

name = models.CharField(max_length=200, verbose_name="Kaardi peakiri", help_text="Sisesta kaardi pealkiri (maksimum tähemärkide arv on 38)", blank=False, null=False)

See the docs. There is no option called name.

Share:
10,350
Odif Yltsaeb
Author by

Odif Yltsaeb

Lifelong IT guy and leader of people. Interesting in doing something awesome and helping others to become awesome too.

Updated on June 13, 2022

Comments

  • Odif Yltsaeb
    Odif Yltsaeb almost 2 years

    ..whatdoyoucallitanyway..

    I have this model:

    class Kaart(models.Model):
        name = models.CharField(max_length=200, name="Kaardi peakiri", help_text="Sisesta kaardi pealkiri (maksimum tähemärkide arv on 38)", blank=False, null=False)
        url = models.CharField(max_length=200, blank=False, null=False, name="Asukoha URL", help_text="Täisasukoht (http://www.domeen.ee/kaart/)")
        kirjeldus = models.TextField(max_length=500, name="Kommentaar", help_text="Informatsioon / viide tegijale (mitte kohustuslik)")
    

    Then i have this form:

    class KaartForm(ModelForm):
        class Meta:
            model = Kaart
    

    And i have this code in my template:

    {% for field in form %}
        <p>
        <label>{{ field.label }}</label>
        <em>{{ field.help_text }}</em>
        {{ field }}
        </p>
    {% endfor %}
    

    The problem is that both field.label and field.name display name, url, kirjeldus instead of the names i have set for them - "Kaardi pealkiri" etc. How do i get to use those instead?