示例#1
0
  def post(self, request, *args, **kwargs):
    form = CountryCreateFormModel(request.POST)

    if self.form.is_valid():
      country = form.save()
      return JsonResponse({ "name" : country.name })

    return self.get(request, *args, **kwargs)
示例#2
0
class CountryCreateView(TemplateView):
    template_name = "countries/register.html"

    def dispatch(self, request, *args, **kwargs):
        self.form = CountryCreateFormModel(request.POST or None)
        return super().dispatch(request, *args, **kwargs)

    def get_context_data(self, *args, **kwargs):
        return {'form': self.form}

    def post(self, request, *args, **kwargs):
        if self.form.is_valid():
            country = self.form.save()
            return JsonResponse({'name': country.name})
        return self.get(request, *args, **kwargs)
示例#3
0
 def dispatch(self, request, *args, **kwargs):
     self.form = CountryCreateFormModel(request.POST or None)
     return super().dispatch(request, *args, **kwargs)