From 70fe9fe1ea6bdd6cd0801f4a9dbc208eae7fc5f8 Mon Sep 17 00:00:00 2001 From: KK Date: Fri, 15 Dec 2023 17:14:10 +0100 Subject: [PATCH] refactor: display values of fields in display view - use _get_FIELD_display() to set field values to fix display values of choices using enumeration types (uses choices labels over values) - simplify check for exclude_fields by moving it into existing function call Closes: #506 --- apis_core/apis_entities/detail_generic.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/apis_core/apis_entities/detail_generic.py b/apis_core/apis_entities/detail_generic.py index 922d8af60..9ce6e3ee0 100644 --- a/apis_core/apis_entities/detail_generic.py +++ b/apis_core/apis_entities/detail_generic.py @@ -126,9 +126,11 @@ def get(self, request, *args, **kwargs): ] entity_settings = get_entity_settings_by_modelname(self.entity) exclude_fields.extend(entity_settings.get("detail_view_exclude", [])) - for field, value in model_to_dict(self.instance).items(): - if field not in exclude_fields: - relevant_fields.append((self.instance._meta.get_field(field), value)) + + for field_name in model_to_dict(self.instance, exclude=exclude_fields): + field_obj = self.instance._meta.get_field(field_name) + value = self.instance._get_FIELD_display(field_obj) + relevant_fields.append((field_obj, value)) return HttpResponse( template.render(