def add_gallery(request): if request.method == "POST": form = PhotoGalleryForm(request.POST, request.FILES) if form.is_valid(): gallery = form.save() return redirect('/#gallery-{}'.format(gallery.id)) else: form = PhotoGalleryForm() return render(request, 'add_gallery.html', { 'form': form, })
def edit_gallery(request, pk): gallery = PhotoGallery.objects.get(id=pk) if request.method == "POST": form = PhotoGalleryForm(request.POST, request.FILES, instance=gallery) if form.is_valid(): gallery = form.save() return redirect('/#gallery-{}'.format(gallery.id)) else: form = PhotoGalleryForm(instance=gallery) return render(request, 'add_gallery.html', { 'form': form, })