我有两件事:
如何将这些列表合并到django表单中,其中的产品类似于html here。
所需的表格将允许用户为每种水果(苹果,柠檬,杨梅)选择一个答案('卖','制作','两者')
我从这开始:
class MyForm(forms.Form):
doing = forms.ModelMultipleChoiceField(
queryset=fruits,
widget=forms.Select(choices=choices),
)
答案 0 :(得分:0)
我找到了一个这样的快速解决方案:
FRUITS = [
'apples', 'lemons', 'strawberries',
] # hardcoded like here or from db
ANSWERS = [
(0, u''),
(1, u'selling'),
(2, u'making'),
(3, u'both'),
] # hardcoded like here or from db
class ProblematicForm(forms.Form):
# regluar fields goes here, like:
regular_field = forms.CharField()
def __init__(self, *args, **kwargs):
super(ProblematicForm, self).__init__(*args, **kwargs)
for name in FRUITS:
# Here we add our problematic fields
self.fields[name] = forms.ChoiceField(choices=ANSWERS)
这不会给出fieldset(就像在链接的例子中一样),但它不会。 那是\ o /