Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add child_kwargs to PolymorphicSerializer #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

NDevox
Copy link

@NDevox NDevox commented Feb 8, 2021

This enables passing in a dictionary param, child_kwargs, to
a PolymorphicSerializer. In doing so the child_kwargs will not
be applied to the Polymorphic Serializer - but will be applied to
the child serializers alongside kwargs.

This resolves issue #33

This enables passing in a dictionary param, `child_kwargs`, to
a PolymorphicSerializer. In doing so the `child_kwargs` will not
be applied to the Polymorphic Serializer - but will be applied to
the child serializers alongside `kwargs`.
@codecov
Copy link

codecov bot commented Feb 8, 2021

Codecov Report

Merging #34 (d78be9a) into master (69923ad) will increase coverage by 0.07%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master      #34      +/-   ##
==========================================
+ Coverage   93.10%   93.18%   +0.07%     
==========================================
  Files           1        1              
  Lines          87       88       +1     
==========================================
+ Hits           81       82       +1     
  Misses          6        6              

@denisorehovsky
Copy link
Owner

denisorehovsky commented Mar 15, 2021

@NDevox Hi, thanks for the PR. If I understand correctly, it passes the same child kwargs to every child serializer, correct? What if I want to pass different parameters to different child serializers? Especially, when it comes to drf-flex-fields, it should be very common to want something like that.

@NDevox
Copy link
Author

NDevox commented Mar 15, 2021

Yep that is the crux of the PR. Interesting idea on having type specific kwargs.

Definitely possible, question is what would be the best API for this? Do we want to do it based on specific object instance? or specific serializer type? My specific usecase for instance would want to do it on serializer type.

Could do something like:

child_kwargs = {
    "SerializerType": serializer_type_kwargs,  # Applies only to SerializerType children
    "*": global_child_kwargs,  # Applies to all children.
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants