def CreateAssets(request): if request.method == 'POST': form = AssetsListForm(request.POST) if form.is_valid(): form.save() #cd = form.cleaned_data return HttpResponseRedirect(reverse('sadmin:assetslist')) else: print '数据不符合要求' else: form = AssetsListForm() #return render(request, 'create_host.html', locals()) #print form return render_to_response('assets/create_assets.html', {'form': form},RequestContext(request))
def EditAssets(request,assets_id): try: a = get_object_or_404(Assets, pk=assets_id) except Assets.DoesNotExist: raise Http404("资产不存在..") # return render_to_response('create_assets.html', {'form': a}) if request.method == "POST": form = AssetsListForm(request.POST, instance=a) if form.is_valid(): post = form.save(commit=False) #post.author = request.user post.save() return redirect('sadmin:assetslist',) #return HttpResponseRedirect(reverse('mtime:post_detail', args=(post.pk,))) else: form = AssetsListForm(instance=a) return render_to_response('assets/create_assets.html', {'form': form},RequestContext(request))