def create_doc(request): if request.method == 'GET': form = DocumentForm() return render_to_response('docs/doc.html', {'form':form}, context_instance=RequestContext(request)) if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): doc = form.save() return redirect(reverse_lazy('cms:docs_index')) else: return render_to_response('docs/doc.html', {'form':form}, context_instance=RequestContext(request))
def update_doc(request, doc_id): doc = Document.objects.get(id=doc_id) if request.method == 'GET': form = DocumentForm(instance=doc) return render_to_response('docs/doc.html', {'editing':True, 'form':form}, context_instance=RequestContext(request)) if request.method == 'POST': form = DocumentForm(request.POST, request.FILES, instance=doc) if form.is_valid(): doc = form.save() return redirect(reverse_lazy('cms:docs_index')) else: return render_to_response('docs/doc.html', {'editing':True, 'form':form}, context_instance=RequestContext(request))