From 2b979d43566311d9dc0411957565966e0a17238d Mon Sep 17 00:00:00 2001 From: Julien Syx Date: Thu, 2 Jul 2015 14:15:43 +0200 Subject: [PATCH] Adding recursion on child of List Field --- rest_framework/metadata.py | 3 +++ tests/test_metadata.py | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/rest_framework/metadata.py b/rest_framework/metadata.py index 14d41b979..6bc18b3ab 100644 --- a/rest_framework/metadata.py +++ b/rest_framework/metadata.py @@ -131,6 +131,9 @@ class SimpleMetadata(BaseMetadata): if value is not None and value != '': field_info[attr] = force_text(value, strings_only=True) + if getattr(field, 'child', None): + field_info['child'] = self.get_field_info(field.child) + if not field_info.get('read_only') and hasattr(field, 'choices'): field_info['choices'] = [ { diff --git a/tests/test_metadata.py b/tests/test_metadata.py index 6510a7070..f7aab8973 100644 --- a/tests/test_metadata.py +++ b/tests/test_metadata.py @@ -67,6 +67,11 @@ class TestMetadata: char_field = serializers.CharField( required=False, min_length=3, max_length=40 ) + list_field = serializers.ListField( + child=serializers.ListField( + child=serializers.IntegerField() + ) + ) class ExampleView(views.APIView): """Example view.""" @@ -119,6 +124,22 @@ class TestMetadata: 'label': 'Char field', 'min_length': 3, 'max_length': 40 + }, + 'list_field': { + 'type': 'list', + 'required': True, + 'read_only': False, + 'label': 'List field', + 'child': { + 'type': 'list', + 'required': True, + 'read_only': False, + 'child': { + 'type': 'integer', + 'required': True, + 'read_only': False + } + } } } }