Skip to content

🚧 [#105] added broken polymorphic-serializer actor with tests #106

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

Closed
wants to merge 6 commits into from

Conversation

bart-maykin
Copy link
Contributor

fixes #105

Changes:

Changed the actor HyperlinkedModelSerializer to PolymorphicSerializer and updated tests acoridingly
Removed Medewerker, GeautomatiserdeActor en Org. Eenheid resources

Copy link
Contributor

@annashamray annashamray left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some comments how to make it work:

  1. PolymorphicSerializerMetaclass dynamically createactor_identificaties a serializer for group field (here it's actor_identificatie). It uses related fields of Actor model to construct source attribute. For example, if actor_type = 'medewerker', then it will create a serializer class with a field actor_identificatie with source = medewerker.

    If you have OneToOne relations between Actor and Medewerker models, this would work. But you have FK relations, i.e. actor.medewerker is a manager and not a model.instance. To fix it I suggest any of two options:

  2. I don't think PolymorphicSerializerMetaclass supports cases then discriminator model and serializer field have different names. So I'd just rename soort_actor to actor_type, since it's the easiest

@annashamray
Copy link
Contributor

  1. PolymorphicSerializer doesn't have create andupdate, so you need to implement them by yourself if you want this resource to be writeable. For read-only resources you can leave it as it is.
  2. NestedGegevensGroepMixin and PolymorphicSerializer don't work together. I'd suggest removing NestedGegevensGroepMixin, because you need to write custom create andupdate anyway

@bart-maykin bart-maykin force-pushed the feature/100-basic-crud branch 7 times, most recently from 635aaa4 to f0c0533 Compare November 24, 2023 14:43
Base automatically changed from feature/100-basic-crud to master November 24, 2023 14:53
@danielmursa-dev danielmursa-dev deleted the feature/105-polymophic-serializers branch April 23, 2025 13:57
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.

Polymorphic Serializers
2 participants