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

Support for Django 1.8 ArrayField #2496

Merged
merged 6 commits into from
Feb 5, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions rest_framework/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -986,15 +986,25 @@ def build_standard_field(self, field_name, model_field):
# Fields with choices get coerced into `ChoiceField`
# instead of using their regular typed field.
field_class = ChoiceField

if not issubclass(field_class, ModelField):
# `model_field` is only valid for the fallback case of
# `ModelField`, which is used when no other typed field
# matched to the model field.
field_kwargs.pop('model_field', None)

if not issubclass(field_class, CharField) and not issubclass(field_class, ChoiceField):
# `allow_blank` is only valid for textual fields.
field_kwargs.pop('allow_blank', None)

if postgres_fields and isinstance(model_field, postgres_fields.ArrayField):
child_model_field = model_field.base_field
child_field_class, child_field_kwargs = self.build_standard_field(
'child', child_model_field
)

field_kwargs['child'] = child_field_class(**child_field_kwargs)

return field_class, field_kwargs

def build_relational_field(self, field_name, relation_info):
Expand Down Expand Up @@ -1337,6 +1347,7 @@ class CharMappingField(DictField):
child = CharField()

ModelSerializer.serializer_field_mapping[postgres_fields.HStoreField] = CharMappingField
ModelSerializer.serializer_field_mapping[postgres_fields.ArrayField] = ListField


class HyperlinkedModelSerializer(ModelSerializer):
Expand Down