def post(self, request, *args, **kwargs): form = Customerform(request.POST, request.FILES) if form.is_valid(): form.save() return redirect('customerlist') else: return redirect('customercreate')
def post(self, request, *args, **kwargs): id = kwargs.get("pk") qs = self.model.objects.get(id=id) form = Customerform(instance=qs, data=request.POST, files=request.FILES) if form.is_valid(): form.save() return redirect('customerlist') else: return render(request, self.template_name, self.context)
class Customerdelete(DeleteView): model = Customerprofile template_name = "Customer/customerdelete.html" form_class = Customerform() context = {} def get(self, request, *args, **kwargs): id = kwargs.get("pk") qs = self.model.objects.get(id=id) self.context['form'] = Customerform(instance=qs) return render(request, self.template_name, self.context) def post(self, request, *args, **kwargs): id = kwargs.get("pk") qs = self.model.objects.get(id=id) qs.delete() return redirect('customerlist')
class Customercreate(CreateView): model = Customerprofile form_class = Customerform() template_name = "Customer/customercreate.html" context = {} def get(self, request, *args, **kwargs): self.context['form'] = self.form_class return render(request, self.template_name, self.context) def post(self, request, *args, **kwargs): form = Customerform(request.POST, request.FILES) if form.is_valid(): form.save() return redirect('customerlist') else: return redirect('customercreate')
class Customeredit(TemplateView): model = Customerprofile form_class = Customerform() template_name = "Customer/customeredit.html" context = {} def get(self, request, *args, **kwargs): id = kwargs.get('pk') qs = self.model.objects.get(id=id) form = Customerform(instance=qs) self.context['form'] = form return render(request, self.template_name, self.context) def post(self, request, *args, **kwargs): id = kwargs.get("pk") qs = self.model.objects.get(id=id) form = Customerform(instance=qs, data=request.POST, files=request.FILES) if form.is_valid(): form.save() return redirect('customerlist') else: return render(request, self.template_name, self.context)
def get(self, request, *args, **kwargs): id = kwargs.get('pk') qs = self.model.objects.get(id=id) form = Customerform(instance=qs) self.context['form'] = form return render(request, self.template_name, self.context)