Skip to content

Commit

Permalink
mes-227: Remove translation fields from API response using get_fields…
Browse files Browse the repository at this point in the history
…() instead of __init__ (#1)
  • Loading branch information
AlbertoMoreta authored Aug 29, 2024
1 parent 37943ec commit 3fa4de5
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions api/mixins/ExcludeTranslationFieldsMixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
class ExcludeTranslationFieldsMixin:
# Exclude the specific language fields from the serializer output

def __init__(self, *args, **kwargs):
super().__init__(args, kwargs)
def get_fields(self):
fields = super().get_fields()
for f in self.Meta.model._meta.fields:
if f.name in self.fields and isinstance(f, TranslationField):
self.fields.pop(f.name)
if f.name in fields and isinstance(f, TranslationField):
del fields[f.name]
return fields

0 comments on commit 3fa4de5

Please sign in to comment.