models.py
PERSON_ACTIONS = (
('1', '01.Allowed to rest and returned to class'),
('2', '02.Contacted parents /guardians'),
('3', '02a.- Unable to Contact'),
('4', '02b.Unavailable - left message'))
class Actions(models.Model):
reportperson = models.ForeignKey(ReportPerson)
action = models.IntegerField('Action type', choices=PERSON_ACTIONS)
forms.py
class PersonActionsForm(forms.ModelForm):
action = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple(), required=False)
class Meta:
model = Actions
fields = ['action']
模板
{{actionform.get_action_display}}
这不显示人类可读格式的表单数据。它也不会从db渲染整数值。
答案 0 :(得分:0)
我想你想要那个:
class PersonActionsForm(forms.ModelForm):
class Meta:
model = Actions
fields = ('action',)
widgets = {
'action': forms.CheckboxSelectMultiple(),
}
请参阅here
答案 1 :(得分:0)