怎么用foreignkey 实现Django下拉选择框
1个回答
展开全部
class ReportForm(forms.Form):
college = forms.ChoiceField(required=True, widget=forms.Select, choices=(),)
def set_choices(self):
colleges = College.objects.all()
self.fields['college'].choices = ()
for college in colleges:
self.fields['college'].choices += [(college.id, college.collegename)]
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询