Skip to content

[Resources] Media Type Choices Field Value is Dropped when POSTing in JSON #125

Closed
@BethanyG

Description

@BethanyG

This is why we test. 🙄

If a resources record is created via POST (using cURL, Postman, charles, or other client), the value in the media_type field (defined as a CHOICES field) is dropped. It is handled OK if the POST is done via the browsable api (which uses a Django form view), but needs to have an additional methods for the DRF serializer to render & save it correctly.

See this Stack Overflow Post & this additional Stack Overflow Post for details on how to fix this.

Essentially, we need to add some variant of:

 media_type = serializers.SerializerMethodField('get_media_type')

# ......

    def get_media_type(self, obj):
        return obj.get_media_type_display()

    def to_internal_value(self, data):
        return data

To resources/serializers.py, so that the internal value is saved, and the "display name" is properly fetched for the return serialization/representation.

Until this is done and checked in, one of the resources tests (test_create_one_resource) will fail.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions