def post(self, request, pk=None):
        star = get_object_or_404(Star, id=pk, owner=self.request.user)
        form = CreateForm(request.POST, request.FILES or None, instance=star)

        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:
         star = get_object_or_404(Star, id=pk, owner=self.request.user)
         form = CreateForm(instance=star)
     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 stars to the model before saving
        star = form.save(commit=False)
        star.owner = self.request.user
        star.save()
        return redirect(self.success_url)
Ejemplo n.º 4
0
    def post(self, request, pk=None) :
        if not pk:
            form = CreateForm(request.POST, request.FILES or None)
        else:
            star = get_object_or_404(Star, id=pk, owner=self.request.user)
            form = CreateForm(request.POST, request.FILES or None, instance=star)

        if not form.is_valid() :
            ctx = {'form' : form}
            return render(request, self.template, ctx)

        # Adjust the model owner before saving
        star = form.save(commit=False)
        star.owner = self.request.user
        star.save()
        return redirect(self.success_url)
 def get(self, request, pk=None):
     form = CreateForm()
     ctx = {'form': form}
     return render(request, self.template, ctx)