class Banner(NewsBase):
'''
轮播图
'''
PRI_CHOICES = [ # 优先级的限制选择范围
(1,'第一级'),
(2,'第二级'),
(3,'第三级'),
(4,'第四级'),
(5,'第五级'),
(6,'第六级')
]
image_url = models.CharField(verbose_name='图片url',max_length=200)
priority = models.IntegerField(verbose_name='优先级',choices=PRI_CHOICES,default=6) # choices参数,限制输入范围.
news = models.OneToOneField('news',on_delete=models.CASCADE) class Meta:
ordering = ['priority','-update_time']
db_table = 'tb_banner'
verbose_name = '轮播图'
verbose_name_plural=verbose_name def __str__(self):
return '<轮播图{}>'.format(self.id)
choices 字段选择限制.类型于'枚举'