我怎样才能获得字段值?我在var Lotnisko中有简单的值a,b,c,d。现在我想用这个vaules创建表单,但是Django只生成这样的HTML输出:
<option>a</option>
<option>b</option>
但我只想要简单的vars,然后在模板中创建一些这样的东西:
{% for a in form.od %}
{{ a.value }}<br>
{% endfor %}
是的,我知道我的语言能力很差;)
Models.py
class BusZLok(models.Model):
Lotnisko = models.CharField(max_length=30)
def __unicode__(self):
return self.Lotnisko
class Meta:
verbose_name = "Lotnisko Odlotu"
verbose_name_plural = "Lotniska Odlotu"
class Kursy(models.Model):
trasa = models.CharField('Nazwa Trasy',max_length=30)
od = models.ForeignKey(BusZLok)
def __unicode__(self):
return self.trasa
class Meta:
verbose_name = "Trasa"
verbose_name_plural = "Trasy"
class RezerwacjaFormOne(forms.ModelForm):
class Meta:
model = Kursy
fields = ['od']