什么是CURD?
CURD顾名思义就是create,update,rearch,delete(所谓的增删改查).
当我们接到一个项目的时候,夸夸夸的就写完表结构,然后就一直写增删改查,增删改查,写了一个月,看似很认真效率很高,但是这里我要严肃的告诉你。你只需要一个配置文件就可以完成对表进行增删改查.什么???你不信??and那么看看。
1.配置文件
配置文件需要放上面?
1.confi [{'q':数据库的字段名,
'title':表单的head名
'display' :1/0 是否可以显示
text:{content:.....
kwargs:{......}}}]
2.数据库内容
3.全局变量,主要针对的是choice
4.分页
msg={ 'config':config, 'data_list':list(data_list), 'global_dict':{ 'user_choice':models.UserInfo.user_choice, }, 'page_str':page_str, } config = [ { 'q': None, 'title': '选项', 'display': 1, 'text': { 'content':'<input type="checkbox"/>' }, 'attrs': {}, }, { 'q': 'id', 'title': 'ID', 'display': 0, 'text':None, 'attrs': {}, }, { 'q': 'username', 'title': '姓名', 'display': 1, 'text':{'content':'{username}', 'kwargs':{'username':'@username'}}, 'attrs': {'edit-enalbe':'true','edit-type':'input', 'name':'username','origin':'@username'}, }, { 'q': 'user_type', 'title': '用户类型', 'display': 1, 'text': {'content': '{n}', # @@ 后面的数据是要选择的元组 # 和一个@的区分开 'kwargs': {'n': '@@user_choice'}}, 'attrs': {'edit-enalbe':'true', 'edit-type':'select' ,'global-name':'user_choice','origin':'@user_type', 'name':'user_type'}, }, { 'q': 'nickname', 'title': '昵称', 'display': 1, 'text': {'content': '{nick}', 'kwargs': {'nick': '@nickname'}}, 'attrs': {'edit-enalbe': 'true', 'edit-type': 'input', 'name':'nickname','origin':'@nickname'}, }, { 'q': 'user2blog__surfix', 'title': '博客地址', 'display': 1, 'text': {'content': '{n}', 'kwargs': {'n': '@user2blog__surfix'}}, 'attrs': {'edit-enalbe':'fault'}, }, { 'q': None, 'title': '操作', 'display': 1, 'text': {'content': '<a href="/index-{nid}">{m}</a>', 'kwargs': {'nid': '@id',"m":'查看详细'}}, 'attrs': {}, }, ]