field types

总览

总共有29种类型

  • ForeignKey
  • OneToOneField
  • BooleanField
  • CharField
  • TextField
  • AutoField
  • BigAutoField
  • BigIntegerField
  • BinaryField
  • CommaSeparatedIntegerField
  • DateField
  • DateTimeField
  • DecimalField
  • DurationField
  • EmailField
  • FileField
  • FilePathField
  • FloatField
  • ImageField
  • IntegerField
  • GenericIPAddressField
  • NullBooleanField
  • PositiveIntegerField
  • PositiveSmallIntegerField
  • SlugField
  • SmallIntegerField
  • TimeField
  • URLField
  • UUIDField

类型说明

BigAutoField

64-bit的 integer,范围 1~9223372036854775807

注:Djangl 1.10新增

BinaryField

A field to store raw binary data.

DateField

A date, represented in Python by a datetime.date instance.

可选属性

  1. auto_now

    • 对象调用save()方法时会更新,可用于last_modified
  2. auto_now_add

    • 对象第一次创建的时候会更新,可用于created_date
    • 字段设置auto_now_add=True即可

注意

  • 字段增加auto_now 或 auto_now_add 属性后,字段将被设置为editable=False,blank=True
  • 日期的时区受到default timezone控制

DateTimeField

A date and time, represented in Python by a datetime.datetime instance.