Title

orm --建表字段--性别选择存储

choices参数说明(models.py--建表.数据库中存入的数据是0/1, 调取数据库可以显示中文女性/男性)

sex_choice = (
    (0, '女性'),
    (1, '男性'),
)

class Author(models.Model):
	name = models.CharField( max_length=32)
	age = models.IntegerField()

	sex_choice = (
		(0, '女性'),
		(1, '男性'),
	)

	sex = models.IntegerField(choices=sex_choice,default=1) #choices关键字固定的

posted @ 2020-12-06 18:38  侠客行|  阅读(455)  评论(0)    收藏  举报