class DocumentOrderView(CsrfExemptMixin, JsonRequestResponseMixin, FormView):
def post(self, request, *args, **kwargs):
self.tree_update(None, self.request_json)
return self.render_json_response({'saved': 'ok'})
@staticmethod
def tree_update(parent_id, children):
for child in children:
Tree.objects.filter(pk=child['id']).update(parent_id=parent_id)
tree_update(child['id'], child.get('children', []))