def post(self, request, *args, **kwargs): form = ListingForm(request.POST) if form.is_valid(): listing = form.save(commit=False) listing.author = request.user listing = form.save() listing.save() return HttpResponseRedirect( reverse_lazy('listing-details-page', args=[listing.slug]))
def listing_submit(request): if request.method == 'POST': form = ListingForm(request.POST) if form.is_valid(): form.save() return redirect('listings_thanks') else: form = ListingForm() return render(request, 'listing-submit.html', {'form': form})
def edit(request, listing_id): listing = get_object_or_404(Listing, pk=listing_id) if not listing.can_edit(request.user): raise PermissionDenied if request.method == "POST": form = ListingForm(data=request.POST, instance=listing) if form.is_valid(): listing = form.save() return redirect(reverse("detail", args=(listing.id,))) else: form = ListingForm(instance=listing) return render(request, "listings/edit.html", {"form": form})
def new(request): ''' Create a new listing with request.user as owner ''' if request.method == 'POST': form = ListingForm(request.POST) if form.is_valid: l = form.save(commit=False) l.owner = request.user l.save() return HttpResponseRedirect(reverse('listings_all')) else: form = ListingForm() return create_object(request, form_class=ListingForm)
def create(request): if request.method == "POST": form = ListingForm(request.POST) if form.is_valid(): listing = form.save(commit=False) listing.owner = request.user listing.save() listing.team.add(request.user) form.save_m2m() if form.cleaned_data["innovation_sandbox"] is True: sendMailToInnovation(listing) return redirect(reverse("detail", args=(listing.id,))) else: form = ListingForm() return render(request, "listings/create.html", {"form": form})
def new(request): ''' Create a new listing with request.user as owner ''' if request.method == 'POST': form = ListingForm(request.POST) if form.is_valid: l = form.save(commit=False) l.owner = request.user l.save() return HttpResponseRedirect(reverse('listings_all')) else: form = ListingForm() return create_object( request, form_class = ListingForm )