0

模型.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)

表格.py

class PersonActionsForm(forms.ModelForm):
    action = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple(), required=False)

    class Meta:
        model = Actions
        fields = ['action']

模板

{{actionform.get_action_display}}

这没有以人类可读的格式显示表单数据。它也没有从 db 呈现整数值。

4

2 回答 2

0

我想你想要的是:

class PersonActionsForm(forms.ModelForm):

    class Meta:
        model = Actions
        fields = ('action',)
        widgets = {
            'action': forms.CheckboxSelectMultiple(),
        }

这里

于 2013-07-17T11:48:55.737 回答
0

模型.get_FOO_display()

如果您不想从表单中的实例呈现值:

{{actionform.instance.get_action_display}}
于 2013-07-17T12:44:36.120 回答