示例#1
0
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,
    })
示例#2
0
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,
    })