def post(self, request, pk=None) : cookie = get_object_or_404(Cookie, id=pk, owner=self.request.user) form = CreateForm(request.POST, request.FILES or None, instance=cookie) if not form.is_valid() : ctx = {'form' : form} return render(request, self.template, ctx)
def get(self, request, pk=None) : if not pk : form = CreateForm() else: cookie = get_object_or_404(Cookie, id=pk, owner=self.request.user) form = CreateForm(instance=cookie) ctx = { 'form': form } return render(request, self.template, ctx)
def post(self, request, pk=None) : form = CreateForm(request.POST, request.FILES or None) if not form.is_valid() : ctx = {'form' : form} return render(request, self.template, ctx) # Add cookies to the model before saving cookie = form.save(commit=False) cookie.owner = self.request.user cookie.save() return redirect(self.success_url)
def post(self, request, pk=None) : if not pk: form = CreateForm(request.POST, request.FILES or None) else: cookie = get_object_or_404(Cookie, id=pk, owner=self.request.user) form = CreateForm(request.POST, request.FILES or None, instance=cookie) if not form.is_valid() : ctx = {'form' : form} return render(request, self.template, ctx) # Cookiejust the model cookies before saving cookie = form.save(commit=False) cookie.owner = self.request.user cookie.save() return redirect(self.success_url)
def get(self, request, pk=None) : form = CreateForm() ctx = { 'form': form } return render(request, self.template, ctx)