[Django]-Overload get_FIELD_display() function

5👍

updated

field = self._meta.get_field('opposition_state')
value = self._get_FIELD_display(field)
👤second

2👍

To override get_FOO_display you need something like this:

field_name = models.PositiveSmallIntegerField('Field', choices=some_choices)

def _get_FIELD_display(self, field):
    f_name = field.name
    if f_name == 'field_name':
        return 'what_you_need'
    return super(YourModelName, self)._get_FIELD_display(field=field)

Leave a comment