Beispiel #1
0
 def get(self, request, pk=None):
     if not pk:
         form = CreateForm()
     else:
         pic = get_object_or_404(Pic, id=pk, owner=self.request.user)
         form = CreateForm(instance=pic)
     ctx = {'form': form}
     return render(request, self.template, ctx)
Beispiel #2
0
    def post(self, request, pk=None):
        pic = get_object_or_404(Pic, 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_name, ctx)

        pic = form.save(commit=False)
        pic.save()

        return redirect(self.success_url)
Beispiel #3
0
    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_name, 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)
Beispiel #4
0
 def get(self, request, pk=None):
     form = CreateForm()
     ctx = {'form': form}
     return render(request, self.template_name, ctx)