django中将model转换为dict的方法

 

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 #[]>}

 

posted on 2018-10-19 20:29  星河赵  阅读(3528)  评论(0编辑  收藏  举报

导航