django的随手笔记

django 操作model字段

CharField(max_length=32)                               字符串

unique=True                                            唯一索引

BooleanField()                            布尔类型:True上架  False 下架

DateTimeField(auto_now_add=True)                    时间

Level_CHOICES=((1,'普通用户'),(2,'Vip用户'))
level=models.SmallIntegerField(choices=Level_CHOICES,default=1)

ManyToManyField(to='表名')                           多对多绑定
through='表名'                                       多对多在加表

DecimalField(max_digits=9,decimal_places=2)           小数点数字
max_digits=9                                          最大多少位
decimal_places=2                                       小数点后面几位

IntegerField()                                         整数
TextField                                            一个很大的文本字段
原文地址:https://www.cnblogs.com/songkaixuan/p/13447732.html