Based on James answer. You can move PERSON_ACTIONS to your model and import it into the form.
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'), ) PERSON_ACTIONS_DICT = dict(PERSON_ACTIONS) class Actions(models.Model): report = models.ForeignKey(Report) action = models.IntegerField('Action type') def action_as_text(self): return PERSON_ACTIONS_DICT.get(str(self.action), None)
forms.py:
from .models import PERSON_ACTIONS class PersonActionsForm(forms.ModelForm): action = forms.MultipleChoiceField( widget=forms.CheckboxSelectMultiple(), choices=PERSON_ACTIONS, required=False, label= u"Actions" )
Get actions in views.py :
actions = Actions.objects.filter(....) return render(request, 'your_template.html', { ..... 'actions': actions })
... and draw it in the template:
{% for action in actions %} {{ action.action_as_text }} {% endfor %}
Hope this helps.
source share