2019独角兽企业重金招聘Python工程师标准>>>

Field types

The generated Form class will have a form field for every model field. Each model field has a corresponding default form field. For example, a CharField on a model is represented as a CharField on a form. A model ManyToManyField is represented as aMultipleChoiceField. Here is the full list of conversions:

Model field Form field
AutoField Not represented in the form
BigIntegerField IntegerField with min_value set to -9223372036854775808 andmax_value set to 9223372036854775807.
BooleanField BooleanField
CharField CharField with max_length set to the model field's max_length
CommaSeparatedIntegerField CharField
DateField DateField
DateTimeField DateTimeField
DecimalField DecimalField
EmailField EmailField
FileField FileField
FilePathField CharField
FloatField FloatField
ForeignKey ModelChoiceField (see below)
ImageField ImageField
IntegerField IntegerField
IPAddressField IPAddressField
ManyToManyField ModelMultipleChoiceField (see below)
NullBooleanField CharField
PhoneNumberField USPhoneNumberField (from django.contrib.localflavor.us)
PositiveIntegerField IntegerField
PositiveSmallIntegerField IntegerField
SlugField SlugField
SmallIntegerField IntegerField
TextField CharField with widget=forms.Textarea
TimeField TimeField
URLField URLField with verify_exists set to the model field's verify_exists
New in Django 1.2: The  BigIntegerField is new in Django 1.2.

As you might expect, the ForeignKey and ManyToManyField model field types are special cases:

  • ForeignKey is represented by django.forms.ModelChoiceField, which is a ChoiceField whose choices are a model QuerySet.
  • ManyToManyField is represented by django.forms.ModelMultipleChoiceField, which is a MultipleChoiceField whose choices are a model QuerySet.

In addition, each generated form field has attributes set as follows:

  • If the model field has blank=True, then required is set to False on the form field. Otherwise, required=True.
  • The form field's label is set to the verbose_name of the model field, with the first character capitalized.
  • The form field's help_text is set to the help_text of the model field.
  • If the model field has choices set, then the form field's widget will be set to Select, with choices coming from the model field's choices. The choices will normally include the blank choice which is selected by default. If the field is required, this forces the user to make a selection. The blank choice will not be included if the model field has blank=False and an explicitdefault value (the default value will be initially selected instead).

Finally, note that you can override the form field used for a given model field. See Overriding the default field types or widgetsbelow.

转载于:https://my.oschina.net/tenking/blog/29447

Field types相关推荐

  1. Django 数据库常见 Field Types

    1.AutoField 如果没有指明主键,就会产生一个自增的主键. 2.BigIntegerField 64位的整型数值,从 -2^63 (-9223372036854775808) 到 2^63-1 ...

  2. ArcGIS中Field 的 Field Precision和Field Scale

    (适用于Float 和Double 类型,在GeoDatabase中不需要指定) Field Scale:小数点右边可以有多少位 Field Precision:小数点左边再加Field Scale可 ...

  3. ABAP性能实例七例

    一.SQL Interface 1.Select ... Where vs. Select + Check 用Select - Where语句效率比Select + Check语句要高,例如: SEL ...

  4. es 时间字段聚合_Elasticsearch 聚合(aggregation)查询返回所有

    Elasticsearch做查询的时候,很多情况下,有一些查询满足不了我们的要求,这个时候,我们用Elasticsearch的聚合(aggregation)函数,下面讲讲aggregation的使用姿 ...

  5. 我使用Python和Django在自己的网站上建立了一个会员专区。 这是我学到的东西。

    I decided it was time to upgrade my personal website in order to allow visitors to buy and access my ...

  6. Django源码分析9:model.py表结构的初始化概述

    django源码分析 本文环境python3.5.2,django1.10.x系列 django源码分析-model概述 Django项目中提供了内置的orm框架,只需要在models.py文件中添加 ...

  7. How to reduce Index size on disk?减少ES索引大小的一些小手段

    ES索引文件瘦身总结如下: 原始数据: (1)学习splunk,原始data存big string (2)原始文件还可以再度压缩 倒排索引: (1)去掉不必要的倒排索引信息:例如文件位置倒排._sou ...

  8. Symfony2CookBook:如何创建自定义的表单域类型

    原文出处:http://symfony.com/doc/2.1/cookbook/form/create_custom_field_type.html 原文作者:symfony.com 授权许可:创作 ...

  9. 各类web服务器 http access log获取用户和代理ip

    IIS.apache.nginx日志中获取访客真实IP的解决方案 http://bbs.jiasule.com/thread-3957-1-1.html 一.        IIS Web服务器解决方 ...

最新文章

  1. 为你揭示最危害程序员职业生涯的三大观念
  2. ElasticSearch Shard——本质上是做分布式扩展,副本对于集群的稳定性有很强的影响...
  3. 汇编语言--CMOS RAM芯片
  4. 2018.8.8笔记
  5. java框架----commonmark的使用(一)
  6. es6变量赋值重命名
  7. 基础【循环】-----(枚举器)------(转)
  8. java jui 正则表达式_常规正则表达式练习
  9. popupmenu java_Java基于JPopupMenu实现系统托盘的弹出菜单,解决PopupMenu弹出菜单中文乱码...
  10. feach同步 git_git fetch 更新远程代码到本地仓库
  11. javascript监听键盘事件 - 如表单enter回车提交
  12. 搭载“可信隐私沙盒”技术 蚂蚁集团联合荣耀手机从源头防范电信诈骗
  13. mysql备份的三种方式
  14. 手机组态软件_安卓平板组态软件​_移动端组态
  15. 腾讯微博开放平台的工作效率真差
  16. 智慧林草信息化解决方案(森林防火应急指挥系统)
  17. 【无人机】基于Matlab实现高效局部地图搜索算法附论文
  18. AI 新技术革命将如何重塑就业和全球化格局?深度解读 UN 报告(上篇)
  19. bing搜索分析网站的方法
  20. 数据库重组函数reorg

热门文章

  1. 极品:蓝丽网 - Vml图像画板.2003 web上的PhotoShop
  2. 自定义GridView分页模板
  3. 迁移博客到香港虚拟空间
  4. 设计模式之职责链模式(Chain of Responsibility)摘录
  5. python如何控制程序的运行顺序_Python流程控制-1 顺序执行
  6. a和a数值大小 计算机,Java求s=a+aa+aaa+aaaa+aa...a的值
  7. python dataframe显示网格_python dataframe 输出结果整行显示的方法
  8. c++ 测试串口速率_Raspberry Pi Zero W:串口(UART)的配置和使用
  9. 随机森林 java_机器学习weka,java api调用随机森林及保存模型
  10. ios采用什么技术_在不锈钢技术成熟的今天,为什么汽车不采用呢?不仅仅是价格问题...