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的方法的更多相关文章

  1. Django 资源 与 知识 Django中自建脚本并使用Django环境 model中的save()方法说明 filter()用法

    Django 资源 与 知识 Django中自建脚本并使用Django环境 model中的save()方法说明 filter()用法 2018/11/06 Chenxin 资料说明 Django基础入 ...

  2. Java中将对象转换为Map的方法

    将对象转换为Map的方法,代码如下: /** * 将对象转成TreeMap,属性名为key,属性值为value * @param object 对象 * @return * @throws Illeg ...

  3. Javascript中将数字转换为中文的方法

    //js实现将数字1234转化为汉字字符串(一千二百三十四)(或大写汉字壹仟贰佰叁拾肆): /*阿拉伯数字转中文数字 中文数字的特点: 每个计数数字都跟着一个权位,权位有:十.百.千.万.亿. 以“万 ...

  4. C语言中将数字转换为字符串的方法

    C语言提供了几个标准库函数,可以将任意类型(整型.长整型.浮点型等)的数字转换为字符串.以下是用itoa()函数将整数转换为字符串的一个例子: # include <stdio. h># ...

  5. django 将model转换为字典

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

  6. C语言中将字符串转换为数字的方法

    C语言提供了几个标准库函数,可以将字符串转换为任意类型(整型.长整型.浮点型等)的数字.以下是用atoi()函数将字符串转换为整数的一个例子: # include <stdio. h># ...

  7. 将java中数组转换为ArrayList的方法实例(包括ArrayList转数组)

    方法一:使用Arrays.asList()方法   1 2 String[] asset = {"equity", "stocks", "gold&q ...

  8. DataTable和DataRow利用反射直接转换为Model对象的扩展方法类

    DataTable和DataRow利用反射直接转换为Model对象的扩展方法类   /// <summary> /// 类 说 明:给DataTable和DataRow扩展方法,直接转换为 ...

  9. Django model distinct 的使用方法

    原文: 今天突然有人问起在 django 的 model 里面怎么用 distinct, 对于这种东西,我一向的观点是查看django 的在线文档.于是不加思索的根据在线文档给出了答案,但结果很让人沮 ...

随机推荐

  1. 【RS】CoupledCF: Learning Explicit and Implicit User-item Couplings in Recommendation for Deep Collaborative Filtering-CoupledCF:在推荐系统深度协作过滤中学习显式和隐式的用户物品耦合

    [论文标题]CoupledCF: Learning Explicit and Implicit User-item Couplings in Recommendation for Deep Colla ...

  2. Oracle 12C -- ADRCI查看DDL日志

    $ adrci ADRCI: Release - Production on Tue Nov :: Copyright (c) , , Oracle and/or its affiliates. Al ...

  3. 【转】标准C++类std::string的内存共享和Copy-On-Write技术

    1.             概念 Scott Meyers在<More Effective C++>中举了个例子,不知你是否还记得?在你还在上学的时候,你的父母要你不要看电视,而去复习功 ...

  4. Bitter Sweet Symphony

    当我写下这段话时,另一个我觉醒了. 时间仿佛一下子从2013年的末尾跳到了2014年了,是那么的猝不及防.1990——2014,24岁了,一瞬间,不知不觉已经走过了24个岁月了.过去,我时常会反省着, ...

  5. nginx+php-fpm性能参数优化原则

    1.worker_processes 越大越好(一定数量后性能增加不明显)   2.worker_cpu_affinity 所有cpu平分worker_processes 要比每个worker_pro ...

  6. wget for windows

    那么,来尝试下wget for windows 吧. 什么是wget? wget是一个强力方便的命令行下的下载工具,可以通过HTTP和FTP协议(两种最广泛的互联网协议)从因特网中检索并获取文件. 此 ...

  7. adb 切换android输入法

    自动化测试执行时,使用了appium输入法,再手动使用时,需要进入设置里面进行切换.adb 也提供了一条命令使用命令切换 1.找出android里面有多少输入法:adb shell ime list ...

  8. Eclipse 快速提取一个方法 (重构)

    选择一块代码并将其转换为一个方法.Eclipse 会自动地推知方法参数及返回类型. 我们有的时候方法太大,但是自己复制粘贴重构又比较麻烦 eclispe拥有这个功能 alt+shift+m 也可以右键 ...

  9. kafka 监控(eagle)

    topic:创建时topic名称 partition:分区编号 offset:表示该parition已经消费了多少条message logSize:表示该partition已经写了多少条message ...

  10. css animation和keyframes

    keyframes应用在animation上,animation应用在元素上. <html> <style type="text/css"> .div1 { ...