在模型中干燥以捕获所有值

时间:2018-11-18 02:05:15

标签: python django

是否有一种更干净的方法来获取“ ALL”值,而不是对所有值进行硬编码?例如,如果我在此处添加了新值,则还需要手动添加该项目:

class EntitySharedLinkPermission(models.Model):

    OFF = None
    COMPANY_VIEW = "Company View"
    COMPANY_EDIT = "Company Edit"
    PUBLIC_VIEW = "Public View"
    PUBLIC_EDIT = "Public Edit"
    ALL_PERMISSIONS = [
     EntitySharedLinkPermission.OFF,
     EntitySharedLinkPermission.COMPANY_VIEW,
     EntitySharedLinkPermission.COMPANY_EDIT,
     EntitySharedLinkPermission.PUBLIC_VIEW,
     EntitySharedLinkPermission.PUBLIC_EDIT
    ]

0 个答案:

没有答案