Django Crispy forms内嵌单选按钮不';我不工作
不确定我做错了什么,但这只是显示普通的单选按钮,而不是内联的看起来像是一个简单的疏忽:在Django Crispy forms内嵌单选按钮不';我不工作,django,django-crispy-forms,Django,Django Crispy Forms,不确定我做错了什么,但这只是显示普通的单选按钮,而不是内联的看起来像是一个简单的疏忽:在\uuuuu init\uuuuu方法中,您需要设置self.helper属性,而不是创建名为helper的变量。这应该适合您: class RatingForm(forms.Form): def __init__(self, *args, lista_de_productores, **kwargs): super(forms.Form, self).__init__(*args, **kwargs
\uuuuu init\uuuuu
方法中,您需要设置self.helper
属性,而不是创建名为helper
的变量。这应该适合您:
class RatingForm(forms.Form):
def __init__(self, *args, lista_de_productores, **kwargs):
super(forms.Form, self).__init__(*args, **kwargs)
for p in lista_de_productores:
CHOICES = (('1', '1',), ('2', '2',), ('3', '3',) , ('4', '4',) , ('5', '5',))
self.fields[str(p)] = forms.ChoiceField(required=True, widget=forms.RadioSelect(), choices=CHOICES)
helper = FormHelper()
helper.layout = Layout(
InlineRadios(str(p))
)
class RatingForm(forms.Form):
def __init__(self, *args, lista_de_productores, **kwargs):
super(forms.Form, self).__init__(*args, **kwargs)
for p in lista_de_productores:
CHOICES = (('1', '1',), ('2', '2',), ('3', '3',) , ('4', '4',) , ('5', '5',))
self.fields[str(p)] = forms.ChoiceField(required=True, widget=forms.RadioSelect, choices=CHOICES)
# set the self.helper property:
self.helper = FormHelper()
self.helper.layout = Layout(
InlineRadios(str(p))
)