code: def handle_ajax_method(self, request, method):
          response = {}
          def get_param(request, name):
              try:
                  return request.POST[name]
              except KeyError:
                  return request.GET.get(name, None)
          widget_id = get_param(request, "widget_id")
          class_name = get_param(request, "class_name")
          if method in 'widget_content':
              return self.render_widget(request, widget_id)
          if method == 'region':
              return self.render_region(request)
          if widget_id:
              widget = get_widget_from_id(widget_id)
              try:
                  func = getattr(widget, method)
              except AttributeError:
                  response["exception"] = "%s method is not implmented on %s" % (
                      method, widget)
              else:
                  response["result"] = func(request)
          elif class_name:
              try:
                  cls = get_model(*class_name.split('.'))
              except Exception as e:
                  response["exception"] = str(e)
                  return JsonResponse(data=response)
              if method == "render_preview":
                  FormCls = modelform_factory(cls, exclude=('pk', 'id'))
                  form = FormCls(request.POST)
                  if form.is_valid():
                      widget = cls(**form.cleaned_data)
                      request.frontend_editing = False
                      try:
                          content = widget.render(**{'request': request})
                      except Exception as e:
                          response['result'] = widget.handle_exception(request, e)
                      else:
                          response['result'] = content
                      response['id'] = widget_id
                  else:
                      response['result'] = form.errors
                      response['id'] = widget_id
              else:
                  try:
                      func = getattr(cls, method)
                  except Exception as e:
                      response["exception"] = str(e)
                  else:
                      response["result"] = func(request)
          return JsonResponse(data=response)