Django Rest Framework Dictionary Field Django Rest Framework Dictionary Field mongodb mongodb

Django Rest Framework Dictionary Field


Rather than deal with the dictionary field in the Serializer's restore_object, you'll probably end up with something slightly cleaner, if instead you use a custom field for the dictionary field, that manages converting between the dictionary representation and internal char based storage.

You'll want to subclass serializers.WritableField and override the to_native() and from_native methods.

Relevant docs here.


Note: WritableField class that was present in version 2.x no longer exists. You should subclass Field and override to_internal_value() if the field supports data input.


Update: As of 3.0.4 you can now use serializers.DictField... http://www.django-rest-framework.org/api-guide/fields/#dictfield