我有一个模型:
class Questionnaire(models.Model):
q1 = "What is your favourite colour?"
a1 = models.CharField()
我想使用 ModelForm 并覆盖这样的标签:
class QuestionnaireForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(QuestionnaireForm, self).__init__(*args, **kwargs)
self.fields['a1'].label = q1
class Meta:
model = Questionnaire