def photo_edit(request, pid): photo = get_object_or_404(Photo, pk = pid) if request.method == 'POST': form = photoForm(request.POST, request.FILES, instance = photo) if form.is_valid(): p = form.save() photo_category_set(p, form.cleaned_data['category']) messages.info(request, "Picture details updated") return HttpResponseRedirect(reverse('dashboard_photos')) else: form = photoForm(instance = photo) return render(request, 'dashboard/photo_edit.html', locals())
def upload(request): where = 'upload' if request.method == 'POST': form = photoForm(request.POST, request.FILES) if form.is_valid(): p = form.save() msg = "Picture uploaded OK" if form.cleaned_data['category'] is not None: cat = form.cleaned_data['category'] cat.add_photo(p) msg += " and added to category %s" % cat.name messages.info(request, msg) return HttpResponseRedirect(".") else: form = photoForm() return render(request, 'dashboard/upload.html', locals())