本节列举了DJANGO ORM中的各种数据类型的field怎么写
我的bijijilu
自增长字段,默认int,Auto = models.AutoFileld()
bigAuto = models.bigAutoFileld()
二进制数据:Binary = models.BinaryField()
布尔型:Boollean = models.BooleanField()
NullBoolean = models.NullBooleanField()
整型:5个字节:PositiveSmallInteger = models.PositiveSmallIntegerField()
6个字节:SmallInteger = models.SmallIntegerField()
10个字节:PositiveInteger = models.PositiveIntegerField()
11个字节:Integer = models.IntegerField()
20个字节:BigInteger = models.BigIntegerField()
字符串:varchar:Char = models.CharField()
longtext:Text = models.TextField()
时间日期:Data = models.DataField() 年月日
DataTime = models.DataTimeField() 年月日时分秒
Duration = models.DurationField() int
浮点型:Float = FloatField()
Decimal = model.DecimalField()
其他字段:
Email = models.EmailField()
Image = models.ImageField()
File = models.FileField()
FilePath = models.FilePathField()
Url = models.UrlField()
UUID = models.UUIDField()
GenericIPAddress = models.GenericIPAddressField()
# 自增长字段 Auto = models.AutoField() BigAuto = models.BigAutoField() # 二进制数据 Binary = models.BinaryField() # 布尔型 Boolean = models.BooleanField() NullBoolean = models.NullBooleanField() # 整型 PositiveSmallInteger = models.PositiveSmallIntegerField(db_column="age") # 5个字节 SmallInteger = models.SmallIntegerField(primary_key=False) # 6个字节 PositiveInteger = models.PositiveIntegerField() # 10个字节 Integer = models.IntegerField(verbose_name="11个字节大小") # 11个字节 BigInteger = models.BigIntegerField(unique=True) # 20个字节 # 字符串类型 Char = models.CharField(max_length=100, null=True, blank=True, db_index=True) # varchar Text = models.TextField(help_text="这个是longtext") # longtext # 时间日期类型 Date = models.DateField(unique_for_date=True, auto_now=True) DateTime = models.DateTimeField(editable=False, unique_for_month=True, auto_now_add=True) Duration = models.DurationField() # int, Python timedelta实现 # 浮点型 Float = models.FloatField() Decimal = models.DecimalField(max_digits=4, decimal_places=2) # 11.22, 16.34 # 其它字段 Email = models.EmailField() # 邮箱 Image = models.ImageField() File = models.FileField() FilePath = models.FilePathField() URL = models.URLField() UUID = models.UUIDField() GenericIPAddress = models.GenericIPAddressField()
字符串类型:
text=models.TextField() //文本
image=models.imageField() //图片