def add(request): if request.method == 'POST': data = Data() data.name = request.POST['name'] data.email = request.POST['email'] data.phone = request.POST['phone'] data.save() return redirect('home') else: return render_to_response('add.html',context_instance=RequestContext(request))
def ajax_data_add(request): #需要登录才可以访问 if not request.session.get("sess_admin", False): return commons.res_fail(1, "需要登录才可以访问") id = 0 if request.REQUEST.get("id"): id = int(request.REQUEST.get("id")) name = request.REQUEST.get("name") content = request.REQUEST.get("content") if not name or name == "": return commons.res_fail(1, "名称不能为空") elif not content or content == "": return commons.res_fail(1, "内容不能为空") data = None if id != 0: data = Data.objects.get(id = id) else: data = Data() data.name = name data.content = content data.add_time = int(time.time()) data.dataclass_id = int(request.REQUEST.get("dataclass_id")) data.sort = int(request.REQUEST.get("sort")) data.type = int(request.REQUEST.get("type")) data.hits = 0 data.picture = "" data.save() if id != 0: return commons.res_success("更新成功") else: return commons.res_success("添加成功")