码迷,mamicode.com
首页 > 其他好文 > 详细

django 将model转换为字典

时间:2018-09-10 21:54:10      阅读:338      评论:0      收藏:0      [点我收藏+]

标签:review   type   created   bar   cli   mod   leader   zha   http   

from django.forms.models import model_to_dict
from projects.models import ProjectInformation


site = ProjectInformation.objects.get(id=6)
dict = model_to_dict(site)

dict

{‘CRFmethod‘: ‘‘,
 ‘EDCprovider‘: ‘‘,
 ‘acceptancenum‘: ‘‘,
 ‘add_time‘: datetime.datetime(2017, 4, 20, 8, 4, 42, 751202, tzinfo=<UTC>),
 ‘begindate‘: None,
 ‘clinicalassis‘: ‘‘,
 ‘clinicalnum‘: ‘‘,
 ‘created_by‘: ‘‘,
 ‘created_date‘: None,
 ‘enddate‘: None,
 ‘ethicsreviewdate‘: None,
 ‘ethicsreviewpers‘: ‘‘,
 ‘ethicsreviewres‘: ‘‘,
 ‘ethicsreviewunit‘: ‘‘,
 ‘id‘: 6,
 ‘isimport‘: None,
 ‘leaderunit‘: None,
 ‘localcases‘: None,
 ‘medicalequipment‘: ‘‘,
 ‘mequipmenttype‘: ‘‘,
 ‘multicenter‘: ‘‘,
 ‘plannum‘: ‘‘,
 ‘proenname‘: ‘爱上地方‘,
 ‘proname‘: ‘打士大夫‘,
 ‘prostatus‘: ‘‘,
 ‘prosummary‘: ‘‘,
 ‘protype‘: ‘打是否‘,
 ‘regstudy‘: ‘是‘,
 ‘reportdate‘: None,
 ‘reportnum‘: ‘‘,
 ‘reportversion‘: ‘‘,
 ‘researchdesign‘: ‘‘,
 ‘researchtype‘: ‘‘,
 ‘responsible‘: ‘‘,
 ‘studytype‘: ‘器械类‘,
 ‘telephonenum‘: None,
 ‘totalcases‘: None,
 ‘treatmenttype‘: None,
 ‘unitnum‘: None}
技术分享图片

 https://www.cnblogs.com/zhaoyingjie/p/6742879.html

django 将model转换为字典

标签:review   type   created   bar   cli   mod   leader   zha   http   

原文地址:https://www.cnblogs.com/hedianzhan/p/9623242.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!