[Answer]-Django get_FOO_display for custom form not working

1👍

I’m very confused by what you are doing.

            print new.fields['id_answer_2'].value
            print get_id_answer_2_display()

You save(commit=False) a ModelForm which returns a model instance. It should not even have a fields attribute (you would be getting an AttributeError here).

2: you next call get_id_answer_2_display() which doesn’t appear to even be the right field (never mind that you call it as a standalone function).

Your ModelForm suggests you have an answer field, thus to use get_FOO_display, you’d need to call new.get_answer_display()

Leave a comment