Skip to content

Commit

Permalink
support 'group' type; easier field conf override
Browse files Browse the repository at this point in the history
  • Loading branch information
sheppard committed Dec 2, 2020
1 parent adb07be commit 1677135
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions rest/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,21 @@ def get_wq_field_info(self, name, field, model=None):
if not isinstance(field, serializers.FileField):
info['wq:length'] = field.max_length

if isinstance(field, serializers.ListSerializer):
if isinstance(field, serializers.BaseSerializer):
# Nested model with a foreign key to this one
field.child.context['router'] = self.router
if hasattr(field.child, 'get_wq_config'):
child_config = field.child.get_wq_config()
if isinstance(field, serializers.ListSerializer):
info['type'] = 'repeat'
serializer = field.child
else:
info['type'] = 'group'
serializer = field

serializer.context['router'] = self.router
if hasattr(serializer, 'get_wq_config'):
child_config = serializer.get_wq_config()
else:
child_config = {'form': []}
info['type'] = 'repeat'

info['children'] = child_config['form']
for key in ('initial', 'control'):
if key in child_config:
Expand Down Expand Up @@ -281,6 +288,13 @@ def get_wq_field_info(self, name, field, model=None):
if source.get_internal_type() == "TextField":
info['type'] = "text"

if 'wq_config' in field.style:
info.update(field.style['wq_config'])

field_config = getattr(self.Meta, 'wq_field_config', {})
if name in field_config:
info.update(field_config[name])

return info

def get_wq_foreignkey_info(self, model):
Expand Down

0 comments on commit 1677135

Please sign in to comment.