def addfunc(request, obj): if hasattr(models, obj): func = getattr(models, obj) objs = Model_Forms.get_form(func) if request.method == "POST": objs = Model_Forms.get_form(func, request.POST) if objs.is_valid(): print("OK Auth Success") objs.save() base_url = "/".join(request.path.split("/")[:-2]) return redirect(base_url) class_verbose_name = func._meta.verbose_name_plural # 获取自定义表名 return render( request, "Add/index.html", {"forms": objs, "class_verbose_name": class_verbose_name, "classname": obj} )
def addfunc(request,obj): if hasattr(models,obj): func=getattr(models,obj) print("-----------",func,obj) objs = Model_Forms.get_form(func) print("objs------------",objs) if request.method == 'POST': objs = Model_Forms.get_form(func,request.POST) if objs.is_valid(): print("OK Auth Success") objs.save() base_url = "/".join(request.path.split("/")[:-2]) return redirect(base_url) class_verbose_name = func._meta.verbose_name_plural # 获取自定义表名 return render(request,'Add/index.html',{'forms':objs, 'class_verbose_name':class_verbose_name, 'classname':obj,})
def changefunc(request, obj, id): if hasattr(models, obj): func = getattr(models, obj) get_data = func.objects.get(id=id) result_data = Model_Forms.get_form(func, instance=get_data) if request.method == "POST": # print(request.POST) result_data = Model_Forms.get_form(func, request.POST, instance=get_data) if result_data.is_valid(): result_data.save() print("auth ok") base_url = "/".join(request.path.split("/")[:-2]) print(base_url) return redirect(base_url) print(dir(result_data.errors)) print(result_data.errors.get.__getattribute__) print(obj, id) print(type(obj), type(id)) return render(request, "update/update_data.html", {"datas": result_data, "classname": obj, "id": id})