def post(self, request, pk=None) : auto = get_object_or_404(Auto, id=pk, owner=self.request.user) form = CreateForm(request.POST, request.FILES or None, instance=auto) 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: auto = get_object_or_404(Auto, id=pk, owner=self.request.user) form = CreateForm(instance=auto) ctx = {'form': form} return render(request, self.template, ctx)
def post(self, request, pk=None): pic = get_object_or_404(Auto, id=pk, owner=self.request.user) form = CreateForm(request.POST, request.FILES or None, instance=pic) if not form.is_valid(): ctx = {'form': form} return render(request, self.template, ctx) pic.save() return redirect(self.success_url)
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 owner to the model before saving pic = form.save(commit=False) pic.owner = self.request.user pic.save() return redirect(self.success_url)
def post(self, request, pk=None): if pk is None: form = CreateForm(request.POST, request.FILES or None) if not form.is_valid(): ctx = {'form': form} return render(request, self.template, ctx) # Add owner to the model before saving auto = form.save(commit=False) auto.owner = self.request.user auto.save() return redirect(self.success_url) else: auto = get_object_or_404(Auto, id=pk, owner=self.request.user) form = CreateForm(request.POST, request.FILES or None, instance=auto) if not form.is_valid(): ctx = {'form': form} return render(request, self.template, ctx) auto.save() return redirect(self.success_url)
def post(self, request, pk=None): if not pk: form = CreateForm(request.POST, request.FILES or None) else: pic = get_object_or_404(Auto, id=pk, owner=self.request.user) form = CreateForm(request.POST, request.FILES or None, instance=pic) if not form.is_valid(): ctx = {'form': form} return render(request, self.template, ctx) # Adjust the model owner before saving pic = form.save(commit=False) pic.owner = self.request.user pic.save() return redirect(self.success_url)
def get(self, request, pk): pic = get_object_or_404(Auto, id=pk, owner=self.request.user) form = CreateForm(instance=pic) ctx = {'form': form} return render(request, self.template, ctx)
def get(self, request, pk=None): form = CreateForm() ctx = {'form': form} return render(request, self.template, ctx)