zoukankan      html  css  js  c++  java
  • 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 #[]>}
  • 相关阅读:
    暂存
    近期学习规划
    将博客搬至CSDN
    后缀自动机五·重复旋律8
    后缀自动机四·重复旋律7
    拓扑排序
    后缀自动机三·重复旋律6
    后缀自动机二·重复旋律5
    交错和(数位dp)
    博弈专题
  • 原文地址:https://www.cnblogs.com/zhaoyingjie/p/9818614.html
Copyright © 2011-2022 走看看