Skip to content

Commit

Permalink
refactor: display values of fields in display view
Browse files Browse the repository at this point in the history
- 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 incorporating it into existing function call

Closes: #506
  • Loading branch information
koeaw committed Dec 15, 2023
1 parent 5e5a74f commit edc6258
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions apis_core/apis_entities/detail_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit edc6258

Please sign in to comment.