https://docs.djangoproject.com/zh-hans/4.0/ref/models/options/

    abstract,用来继承

    1. class OwnerBaseModel(models.Model):
    2. """节点关系人基础模型"""
    3. name = models.CharField(verbose_name='中文姓名', max_length=4, null=True, blank=True)
    4. email = models.CharField(verbose_name='邮箱前缀', max_length=36, primary_key=True)
    5. phone = models.CharField(verbose_name='手机号码', max_length=11, null=True, blank=True)
    6. class Meta:
    7. abstract = True
    8. def __str__(self):
    9. return f'{self.email}'
    10. class OwnerModel(OwnerBaseModel):
    11. """节点负责人 模型类"""
    12. class Meta:
    13. verbose_name = '节点负责人'
    14. verbose_name_plural = verbose_name
    15. class OwnerLeaderModel(OwnerBaseModel):
    16. """节点负责人LD 模型类"""
    17. class Meta:
    18. verbose_name = '节点负责人LD'
    19. verbose_name_plural = verbose_name

    verbose_name,为数据表增加注释信息

    1. class Meta:
    2. verbose_name = '主机表'
    3. verbose_name_plural = verbose_name

    indexs,增加索引

    1. class Meta:
    2. indexes = [
    3. models.Index(fields=['realname', 'nickname'])
    4. ]

    unique_together,联合唯一

    1. class Meta:
    2. unique_together = ('ip_address', 'port_number')

    ordering,排序,在查询操作时,记录会按照这个排序方式进行显示

    1. class Meta:
    2. # 先根据create_time降序,再根据username升序
    3. ordering = ['-create_time', 'username']

    permissions,权限

    1. class Meta:
    2. permissions = [
    3. ('comment_pulish', '发票评论的权限'),
    4. ]

    default_permissions 默认权限