我正在用 django 做一个动态表单,我需要在字段之间写一些东西。这是代码:
class WayForm(forms.Form):
def __init__(self, *args, **kwargs):
waysNumber = kwargs.pop("waysNumber")
super(WayForm, self).__init__(*args, **kwargs)
CHOICES = (('1','Pista',),('2','Corriol',))
for i in range(waysNumber):
# a label or something to print the WaysNumber and show it to the template
self.fields["Descripcio"+str(i)]= forms.CharField(widget=forms.Textarea(),label="Descripcio"+str(i))
self.fields["Tipus"+str(i)] = forms.ChoiceField(widget=forms.RadioSelect, choices=CHOICES, label="Tipus de camí"+str(i))
可以在这里完成还是我必须在模板中完成?我是怎么做的?谢谢!