django-rest-polymorphic
django-rest-polymorphic copied to clipboard
Add `child_kwargs` to PolymorphicSerializer
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
Codecov Report
Merging #34 (d78be9a) into master (69923ad) will increase coverage by
0.07%
. The diff coverage is100.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
@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.
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.
}