djangonauts / django-rest-framework-hstore

Django Rest Framework tools for django-hstore
MIT License
75 stars 15 forks source link

Refactor HStoreSerializer in order to avoid overriding get_field method #2

Open nemesifier opened 10 years ago

nemesifier commented 10 years ago

https://github.com/djangonauts/django-rest-framework-hstore/blob/master/rest_framework_hstore/serializers.py#L31

An approach like the one used on django-rest-framework-gis might be better for maintainability: https://github.com/djangonauts/django-rest-framework-gis/blob/master/rest_framework_gis/serializers.py#L9

mociepka commented 10 years ago

Or you can simple use property:

@property
def field_mapping(self):
    field_mapping = super(HStoreSerializer, self).field_mapping.copy()
    field_mapping[HStoreDict] = HStoreField
    field_mapping[DictionaryField] = HStoreField
    return field_mapping
nemesifier commented 10 years ago

Thanks. To support also the VirtualFields is not that few lines of code unfortunately.