首页 > 其他 > 详细

django中将model转换为dict的方法

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

 

django中将model转换为dict的方法

 

from django.forms.models import model_to_dict
from user.model import userprofile

model_to_dict(userprofile.model.get(id=100))

d3 = {username: zz_yy, password: zyjzyj}
a = UserProfile()
a.username = zz__e
a.password = 33ff
d3 = model_to_dict(a)
print(d3)

#{‘id‘: None, ‘password‘: ‘33ff‘, ‘last_login‘: None, ‘is_superuser‘: #False, ‘username‘: ‘zz__e‘, ‘first_name‘: ‘‘, ‘last_name‘: ‘‘, #‘email‘: ‘‘, ‘is_staff‘: False, ‘is_active‘: True, ‘date_joined‘: #datetime.datetime(2018, 10, 19, 20, 27, 0, 22740), #‘account_person‘: None, ‘if_show_gift_account‘: False, #‘advertisement_type‘: None, ‘account_type‘: ‘advertiser‘, #‘nick_name‘: None, ‘gender‘: ‘male‘, ‘address‘: None, ‘mobile‘: #None, ‘groups‘: <QuerySet []>, ‘user_permissions‘: <QuerySet #[]>}

 

django中将model转换为dict的方法

原文:https://www.cnblogs.com/zhaoyingjie/p/9818614.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!