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

Refactor HStoreSerializer in order to avoid overriding get_field method #2

Open
nemesifier opened this issue Sep 24, 2014 · 2 comments

Comments

@nemesifier
Copy link
Member

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
Copy link

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
Copy link
Member Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants