【发布时间】:2020-11-22 16:21:41
【问题描述】:
这是写出 models.py 和 forms.py 中所有字段的正确方法吗?我确信必须有一种更简洁的方法来做到这一点,而不是单独列出所有字段并在末尾用数字区分它们。
我研究了 Django FormSets,但我不确定如何将它与 Django WizardForms 一起使用。
谢谢
models.py
class Profile(models.Model):
education_school = models.CharField(max_length=500, null=True, blank=True)
education_degree = models.CharField(max_length=500, null=True, blank=True)
education_field = models.CharField(max_length=100, null=True, blank=True)
education_start = models.CharField(max_length=100, null=True, blank=True)
education_end = models.CharField(max_length=100, null=True, blank=True)
education_grade = models.TextField(null=True, blank=True)
education_description = models.TextField(null=True, blank=True)
education_school2 = models.CharField(max_length=500, null=True, blank=True)
education_degree2 = models.CharField(max_length=500, null=True, blank=True)
education_field2 = models.CharField(max_length=100, null=True, blank=True)
education_start2 = models.CharField(max_length=100, null=True, blank=True)
education_end2 = models.CharField(max_length=100, null=True, blank=True)
education_grade2 = models.TextField(null=True, blank=True)
education_description2 = models.TextField(null=True, blank=True)
education_school3 = models.CharField(max_length=500, null=True, blank=True)
education_degree3 = models.CharField(max_length=500, null=True, blank=True)
education_field3 = models.CharField(max_length=100, null=True, blank=True)
education_start3 = models.CharField(max_length=100, null=True, blank=True)
education_end3 = models.CharField(max_length=100, null=True, blank=True)
education_grade3 = models.TextField(null=True, blank=True)
education_description3 = models.TextField(null=True, blank=True)
education_school4 = models.CharField(max_length=500, null=True, blank=True)
education_degree4 = models.CharField(max_length=500, null=True, blank=True)
education_field4 = models.CharField(max_length=100, null=True, blank=True)
education_start4 = models.CharField(max_length=100, null=True, blank=True)
education_end4 = models.CharField(max_length=100, null=True, blank=True)
education_grade4 = models.TextField(null=True, blank=True)
education_description4 = models.TextField(null=True, blank=True)
education_school5 = models.CharField(max_length=500, null=True, blank=True)
education_degree5 = models.CharField(max_length=500, null=True, blank=True)
education_field5 = models.CharField(max_length=100, null=True, blank=True)
education_start5 = models.CharField(max_length=100, null=True, blank=True)
education_end5 = models.CharField(max_length=100, null=True, blank=True)
education_grade5 = models.TextField(null=True, blank=True)
education_description5 = models.TextField(null=True, blank=True)
forms.py
class ProfileFour(forms.Form):
education_school = forms.CharField()
education_degree = forms.CharField()
education_field = forms.CharField()
education_start = forms.ChoiceField(choices=years)
education_end = forms.ChoiceField(choices=years)
education_grade = forms.CharField(widget=forms.Textarea)
education_description = forms.CharField(widget=forms.Textarea)
education_school2 = forms.CharField()
education_degree2 = forms.CharField()
education_field2 = forms.CharField()
education_start2 = forms.ChoiceField(choices=years)
education_end2 = forms.ChoiceField(choices=years)
education_grade2 = forms.CharField(widget=forms.Textarea)
education_description2 = forms.CharField(widget=forms.Textarea)
education_school3 = forms.CharField()
education_degree3 = forms.CharField()
education_field3 = forms.CharField()
education_start3 = forms.ChoiceField(choices=years)
education_end3 = forms.ChoiceField(choices=years)
education_grade3 = forms.CharField(widget=forms.Textarea)
education_description3 = forms.CharField(widget=forms.Textarea)
education_school4 = forms.CharField()
education_degree4 = forms.CharField()
education_field4 = forms.CharField()
education_start4 = forms.ChoiceField(choices=years)
education_end4 = forms.ChoiceField(choices=years)
education_grade4 = forms.CharField(widget=forms.Textarea)
education_description4 = forms.CharField(widget=forms.Textarea)
education_school5 = forms.CharField()
education_degree5 = forms.CharField()
education_field5 = forms.CharField()
education_start5 = forms.ChoiceField(choices=years)
education_end5 = forms.ChoiceField(choices=years)
education_grade5 = forms.CharField(widget=forms.Textarea)
education_description5 = forms.CharField(widget=forms.Textarea)
【问题讨论】:
标签: python django django-models django-forms django-formwizard