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 MODEL_SERIALIZER_FIELD_MAPPING settings #9507

Conversation

TheSuperiorStanislav
Copy link
Contributor

Add way to extend field mapping for ModelSerializer without redefining.

As of now the only way to do it is to make such hack

class ModelSerializer:
  @property
    def serializer_field_mapping(
        self,
    ) -> dict[type[Field], type[serializers.Field]]:
        """Extend serializer mapping with custom fields."""
        serializer_field_mapping = super().serializer_field_mapping
        serializer_field_mapping[FileField] = CustomField
        serializer_field_mapping[ImageField] = CustomField
        return serializer_field_mapping

But for this users need to do this for every serializer or create a base one. This setting will simplify this and make it easier to extend mapping for custom or unsupported fields.

@TheSuperiorStanislav TheSuperiorStanislav force-pushed the set-up-serializer-field-mapping-setting branch from d00f963 to 760921a Compare August 21, 2024 04:15
@TheSuperiorStanislav TheSuperiorStanislav marked this pull request as ready for review August 21, 2024 05:05
@sevdog
Copy link
Contributor

sevdog commented Sep 4, 2024

This is going to break other integrations with DRF where the serializer_field_mapping was supposed to be a class attribute and not an instance property.

Also currently there are very few changes of get new features merged.

Copy link
Member

@auvipy auvipy left a comment

Choose a reason for hiding this comment

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

I think we do not need this in DRF core now

@tomchristie tomchristie closed this Sep 9, 2024
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.

4 participants