def img_update(request, img_id): img = get_object_or_404(Photo, pk=img_id) if request.method == 'POST': form = ImageForm(request.POST, request.FILES, instance=img) if form.is_valid(): img = form.save() request.user.message_set.create(message="Billedet er blevet opdateret.") return HttpResponseRedirect(reverse('dashboard')) else: form = ImageForm(instance=img) return render_to_response( 'articles/red/img/update.html', {'form': form}, context_instance = RequestContext(request) )
def img_upload(request, article_id): if request.method == 'POST': form = ImageForm(request.POST, request.FILES) if form.is_valid(): article = get_object_or_404(Article, pk=article_id) img = form.save() article.photos.add(img) request.user.message_set.create(message="Billedet er blevet uploadet.") return HttpResponseRedirect(reverse('article_update', args=[article.id])) else: form = ImageForm() return render_to_response( 'articles/red/img/upload.html', {'form': form}, context_instance = RequestContext(request) )