For each field that specifies choices, create a get_ _display method.
(self)
| 1199 | return ".".join(parts) |
| 1200 | |
| 1201 | def __set_field_display(self): |
| 1202 | """For each field that specifies choices, create a |
| 1203 | get_<field>_display method. |
| 1204 | """ |
| 1205 | fields_with_choices = [(n, f) for n, f in self._fields.items() if f.choices] |
| 1206 | for attr_name, field in fields_with_choices: |
| 1207 | setattr( |
| 1208 | self, |
| 1209 | "get_%s_display" % attr_name, |
| 1210 | partial(self.__get_field_display, field=field), |
| 1211 | ) |
| 1212 | |
| 1213 | def __get_field_display(self, field): |
| 1214 | """Return the display value for a choice field""" |