def guest_edit(request, pk): guest = Guest_book.objects.get(pk=pk) if request.method == 'POST': form = GuestForm(request.POST, instance=guest) if form.is_valid(): guest = form.save() return redirect('blog.views.guest_detail', guest.pk) else: form = GuestForm(instance=guest) return render(request, 'blog/guest_form.html', {'form': form, })
def guest_new(request): if request.method == 'POST': form = GuestForm(request.POST) if form.is_valid(): guest = form.save() '''(commit=False) post.author = request.user post.save()''' return redirect('blog.views.guest_detail', guest.pk) else: form = GuestForm() return render(request, 'blog/guest_form.html', {'form': form, })
def adresse(request): if request.method == "POST": form = GuestForm(request.POST) if form.is_valid(): guest = form.save(commit=False) guest.nom = request.user guest.save() envoi = True else: form = GuestForm() return render(request, 'blog/guest_edit.html', locals())