我尝试根据这样的模型记录创建表单:
class ActivityForm(forms.Form):
acts = Activity.objects.all()
for a in acts:
print a
activities = forms.ChoiceField(choices=acts)
当我尝试在模板中显示时,我收到错误:
'Activity' object is not iterable
如何根据活动模型创建包含下拉列表的表单?
答案 0 :(得分:1)
应该是这样的:activities = forms.ModelChoiceField(queryset=acts)