django中将model转换为dict的方法
from django.forms.models import model_to_dictfrom user.model import userprofilemodel_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':, 'user_permissions': }