Skip to content

Commit

Permalink
Merge pull request #81 from rsinger86/issue-78
Browse files Browse the repository at this point in the history
Pass correct init args; only pass them if flex serializer
  • Loading branch information
rsinger86 authored Aug 15, 2021
2 parents b84a0ce + 24b48b7 commit 15eae06
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions rest_flex_fields/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,24 +92,27 @@ def _make_expanded_field_serializer(
serializer_class = field_options
settings = {}

settings["parent"] = self
if type(serializer_class) == str:
serializer_class = self._get_serializer_class_from_lazy_string(
serializer_class
)

settings["context"] = self.context

if name in nested_expand:
settings["expand"] = nested_expand[name]
if issubclass(serializer_class, FlexFieldsSerializerMixin):
settings["parent"] = self

if name in nested_fields:
settings["fields"] = nested_fields[name]
if name in nested_expand:
settings[EXPAND_PARAM] = nested_expand[name]

if name in nested_omit:
settings["omit"] = nested_omit[name]
if name in nested_fields:
settings[FIELDS_PARAM] = nested_fields[name]

if name in nested_omit:
settings[OMIT_PARAM] = nested_omit[name]

if type(serializer_class) == str:
serializer_class = self._get_serializer_class_from_lazy_string(
serializer_class
)

return serializer_class(**settings)
return serializer_class(**settings)

def _get_serializer_class_from_lazy_string(self, full_lazy_path: str):
path_parts = full_lazy_path.split(".")
Expand Down

0 comments on commit 15eae06

Please sign in to comment.