Skip to content

Commit 48fa77c

Browse files
committed
Add child to ListField when using ArrayField
1 parent b844cc4 commit 48fa77c

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

rest_framework/serializers.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,15 +986,25 @@ def build_standard_field(self, field_name, model_field):
986986
# Fields with choices get coerced into `ChoiceField`
987987
# instead of using their regular typed field.
988988
field_class = ChoiceField
989+
989990
if not issubclass(field_class, ModelField):
990991
# `model_field` is only valid for the fallback case of
991992
# `ModelField`, which is used when no other typed field
992993
# matched to the model field.
993994
field_kwargs.pop('model_field', None)
995+
994996
if not issubclass(field_class, CharField) and not issubclass(field_class, ChoiceField):
995997
# `allow_blank` is only valid for textual fields.
996998
field_kwargs.pop('allow_blank', None)
997999

1000+
if postgres_fields and isinstance(model_field, postgres_fields.ArrayField):
1001+
child_model_field = model_field.base_field.base_field
1002+
child_field_class, child_field_kwargs = self.build_standard_field(
1003+
'child', child_model_field
1004+
)
1005+
1006+
field_kwargs['child'] = child_field_class(**child_field_kwargs)
1007+
9981008
return field_class, field_kwargs
9991009

10001010
def build_relational_field(self, field_name, relation_info):

0 commit comments

Comments
 (0)