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

Document api update metadata fields #143

Merged
merged 2 commits into from
Nov 18, 2024

Conversation

bart-maykin
Copy link
Contributor

Fixes #142

Changes

Created new document serializer for metadata field update

Copy link

codecov bot commented Nov 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Files with missing lines Coverage Δ
...c/woo_publications/publications/api/serializers.py 100.00% <100.00%> (+1.61%) ⬆️
src/woo_publications/publications/api/viewsets.py 100.00% <100.00%> (ø)


class Meta(DocumentSerializer.Meta):
fields = DocumentSerializer.Meta.fields
read_only_fields = [
Copy link
Contributor Author

@bart-maykin bart-maykin Nov 14, 2024

Choose a reason for hiding this comment

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

I want to dynamically make all fields that we don't want to edit read_only=True.
This way when we update the parent serializer those fields won't suddenly end up in put/patch endpoints.
But this is a very ugly way of doing it. I wanted to do it by editing the get_field method but because we base this serializer on the DocumentSerializer the super() gave me a lot of trouble while trying to set it up. So I ended up doing it this way. What do you think is a better way of tackling this problem @sergei-maertens ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to manipulate the get_fields within the DocumentSerializer which worked functionally but drf-spectacular didn't detect it so I think that this is the best course of action for now.

…ta fields, created specific serializer for the update and dynamically fill in the read_only_fields excepted the fields we want to edit.
…the DocumentApiAuthorizationAndPermissionTests to include the unsafe actions
@sergei-maertens sergei-maertens force-pushed the feature/142-document-update-metadata-in-admin branch from b17d733 to 15bc6db Compare November 18, 2024 09:40
@sergei-maertens sergei-maertens merged commit 464f7c9 into main Nov 18, 2024
18 checks passed
@sergei-maertens sergei-maertens deleted the feature/142-document-update-metadata-in-admin branch November 18, 2024 09:43
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.

Update document metadata fields in api
2 participants