def picture_create(request): form = PictureForm(request.POST) if form.is_valid(): form.save() return redirect('pictures') else: context = {'form': form} return render(request, 'products/new.html', context)
def edit_picture(request, id): picture = get_object_or_404(Picture, pk=id, user=request.user.pk) if request.method == 'POST': form = PictureForm(request.POST, instance=picture) if form.is_valid(): form.save() return redirect('picture_details', id=picture.id) else: form = PictureForm(instance=picture) context = {'form': form, 'picture': picture} return render(request, 'editpic.html', context)
def add_picture(request): if request.method == 'POST': picture_form = PictureForm(request.POST) if picture_form.is_valid(): new_pic = picture_form.save(commit=False) new_pic.user = request.user picture_form.save() return redirect('/pictures', id=new_pic.id) else: picture_form = PictureForm() return render(request, 'add_picture.html', {'picture_form': picture_form})
def add_picture(request): if request.method == 'POST': form = PictureForm(request.POST) if form.is_valid(): add_pic = form.save(commit=False) add_pic.user = request.user form.save() return redirect('picture_details', id=add_pic.id) else: form = PictureForm() html_response = render(request, 'new_pic.html', {'form': form}) return HttpResponse(html_response)
def new_picture_view(request): if request.method == "POST": form = PictureForm(request.POST) if form.is_valid(): instance = form.save(commit=False) instance.user = request.user form.save() return redirect("picture_details", id=instance.id) else: form = PictureForm() html_response = render(request, "new_picture.html", {"form": form}) return HttpResponse(html_response)
def new_picture(request): if request.method == 'POST': form = PictureForm(request.POST) if form.is_valid(): form.user = request.user form.save() return HttpResponseRedirect('/pictures') else: form = PictureForm() context = {'form': form} response = render(request, 'new_picture.html', context) return HttpResponse(response)
def edit_picture(request, id): picture = get_object_or_404(Picture, id=id, user=request.user.pk) print(picture.user) if request.method == 'POST': picture_form = PictureForm(request.POST, instance=picture) if picture_form.is_valid(): picture_form.save() return redirect('/pictures', id=picture.id) else: picture_form = PictureForm(instance=picture) return render(request, 'edit_picture.html', { 'picture_form': picture_form, 'picture': picture })
def edit_picture(request, id): picture = get_object_or_404(Picture, pk=id, user=request.user.pk) if request.method == 'POST': form = PictureForm(request.POST, instance=picture) if form.is_valid(): form.user = request.user form.save() return HttpResponseRedirect('/pictures/' + str(picture.id)) else: form = PictureForm(instance=picture) context = {'picture': picture, 'form': form} response = render(request, 'edit_picture.html', context) return HttpResponse(response)
def edit_picture_view(request, id): picture = get_object_or_404(Picture, pk=id, user=request.user.pk) if request.method == "POST": form = PictureForm(request.POST) if form.is_valid(): instance = form.save(commit=False) instance.user = request.user form.save() return redirect("picture_details", id=instance.id) else: form = PictureForm(instance=picture) context = {"form": form, "picture": picture} html_response = render(request, "edit_picture.html", context) return HttpResponse(html_response)
def picture_create(request): form = PictureForm(request.POST) if form.is_valid(): new_pic = form.save(commit=False) new_pic.user = request.user new_pic.save() return HttpResponseRedirect('/pictures')
def new_picture_form(request): form = PictureForm(request.POST) if form.is_valid(): new_picture = form.save(commit=False) new_picture.user = request.user new_picture.save() return redirect(reverse('show_all')) else: # Else sends user back to picture_form page. return render(request, 'picture_form.html', {'form': form})
def edit_picture(request, id): obj = get_object_or_404(Picture, id=id, user=request.user.id) if request.method == "POST": form = PictureForm(request.POST, instance=obj) if form.is_valid(): obj = form.save(commit=False) obj.save() return redirect('picture_details', id=obj.id) else: form = PictureForm(instance=obj) return render(request, 'edit_picture.html', {'form': form})
def new_picture(request): form = PictureForm(request.POST) if form.is_valid(): new_picture = form.save(commit=False) new_picture.user = request.user new_picture.save() return redirect('pictures') else: return render(request, 'new_picture_form.html', { 'form': form })
def new_picture(request): if request.method == 'POST': form = PictureForm(request.POST) if form.is_valid(): picture = form.save(commit=False) picture.user = request.user picture.save() return redirect('picture_details', id=picture.id) else: form = PictureForm() context = {'form': form} return render(request, 'createpic.html', context)
def submit_picture(request): if request.method == 'POST': form = PictureForm(request.POST) if form.is_valid(): picture = form.save(commit=False) picture.user = request.user picture.save() return redirect("picture_details", id=picture.id) # return HttpResponseRedirect('/addpic') else: form = PictureForm() context = {'form': form} response = render(request, 'addpicture.html', context) return HttpResponse(response)
def edit_picture(request, id): picture = get_object_or_404(Picture, pk=id, user=request.user.pk) if request.method == 'GET': form = PictureForm(instance=picture) return render(request, 'edit_picture_form.html', { "picture": picture, "form": form }) elif request.method == 'POST': form = PictureForm(request.POST, instance=picture) if form.is_valid(): update_picture = form.save() return redirect(reverse('picture_details', args=[picture.id])) else: context = { 'form': form, 'picture': picture } return render(request, 'edit_picture_form.html', context)
def edit_picture(request, id): picture = get_object_or_404(Picture, pk=id, user=request.user.pk) if request.method == "POST": form = PictureForm(request.POST, instance=picture) if form.is_valid(): updated_picture = form.save() return HttpResponseRedirect( reverse('picture_details', args=[picture.id])) else: form = PictureForm(instance=picture) context = {'form': form, 'picture': picture} html_response = render(request, 'edit_picture.html', context) return HttpResponse(html_response) context = {'picture': picture} html_response = render(request, "edit_picture.html", context) return HttpResponse(html_response)
def picture_edit(request, picture_id): picture = get_object_or_404(Picture, pk=picture_id, user=request.user.pk) form = PictureForm(request.POST) if form.is_valid(): edit_picture = form.save(commit=False) edit_picture.user = request.user edit_picture.id = picture_id edit_picture.save() return redirect( reverse('image_details', kwargs={'picture_id': picture_id})) else: return render( request, 'picture_edit.html', { 'picture': picture, 'picture_id': picture_id, 'form': PictureForm(instance=picture) })