def get_widget_json(self, data): widget = self.get_widget(data['id']) if widget is None: return None widget.set_data(data['data']) return { 'id': data['id'], 'data': widget.to_json(), 'widget': WidgetSerializer(widget).data }
def widgets(self, request, pk=None): zone = self.get_object_or_404(pk) serializer = WidgetSerializer(zone.widgets, many=True) return self.get_paginated_response(serializer.data)
def __init__(self, label, widgets, required=False): super(WidgetField, self).__init__(label, required=required) self.widgets = {} for widget in widgets: self.widgets[widget.id] = WidgetSerializer(widget).data