https://docs.djangoproject.com/zh-hans/4.0/ref/models/options/
abstract,用来继承
class OwnerBaseModel(models.Model):
"""节点关系人基础模型"""
name = models.CharField(verbose_name='中文姓名', max_length=4, null=True, blank=True)
email = models.CharField(verbose_name='邮箱前缀', max_length=36, primary_key=True)
phone = models.CharField(verbose_name='手机号码', max_length=11, null=True, blank=True)
class Meta:
abstract = True
def __str__(self):
return f'{self.email}'
class OwnerModel(OwnerBaseModel):
"""节点负责人 模型类"""
class Meta:
verbose_name = '节点负责人'
verbose_name_plural = verbose_name
class OwnerLeaderModel(OwnerBaseModel):
"""节点负责人LD 模型类"""
class Meta:
verbose_name = '节点负责人LD'
verbose_name_plural = verbose_name
verbose_name,为数据表增加注释信息
class Meta:
verbose_name = '主机表'
verbose_name_plural = verbose_name
indexs,增加索引
class Meta:
indexes = [
models.Index(fields=['realname', 'nickname'])
]
unique_together,联合唯一
class Meta:
unique_together = ('ip_address', 'port_number')
ordering,排序,在查询操作时,记录会按照这个排序方式进行显示
class Meta:
# 先根据create_time降序,再根据username升序
ordering = ['-create_time', 'username']
permissions,权限
class Meta:
permissions = [
('comment_pulish', '发票评论的权限'),
]
default_permissions 默认权限