views:

53

answers:

2

..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?

+5  A: 

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.

celopes
Guess i was reading bit wrong docs. was reading generic field and form field docs...
Zayatzz
A: 

According to the documentation, the ModelForm's widget pulls its label value from the verbose_name attribute.

Hank Gay