def post(self, request): form = HouseForm(request.POST) if not form.is_valid(): ctx = {'form': form} return render(request, self.template, ctx) house = form.save() return redirect(self.success_url)
def post(self, request, pk): house = get_object_or_404(self.model, pk=pk) form = HouseForm(request.POST, instance=house) if not form.is_valid(): ctx = {'form': form} return render(request, self.template, ctx) form.save() return redirect(self.success_url)
def get(self, request, pk): house = get_object_or_404(self.model, pk=pk) form = HouseForm(instance=house) ctx = {'house': house} return render(request, self.template, ctx)
def get(self, request): form = HouseForm() ctx = {'form': form} return render(request, self.template, ctx)
def get(self, request, pk): house = get_object_or_404(self.model, pk=pk) form = HouseForm(instance=house) context = {'form': form} return render(request, self.template, context)