フォーム.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 PersonActionsForm(forms.ModelForm):
action = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple(), choices=PERSON_ACTIONS, required=False)
ビュー.py
def person(request):
action= Actions.objects.filter(reportperson=person_id)
return render(request, 'index.html',
{
'action':action,
})
models.py
class Actions(models.Model):
"""Action list to a report"""
reportperson = models.ForeignKey(ReportPerson)
action = models.IntegerField('Action type',choices=PERSON_ACTIONS)
テンプレート
{{ action.get_action_display }}
選択フィールドのdjango docから、これを行いましたが、機能していません。データベースでは、値は「3」、「4」として保存されます。「02a.-連絡できません」のような値が表示されると予想していました。 02b.利用不可 - 「3」、「4」などの代わりにメッセージを残しました。何も表示されていません。
これを機能させる方法。
ありがとう