AttributeError:模块“Django.db.models”没有属性“IntegerChoices”

2024-10-01 13:34:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个无法解决的问题,启动服务器时,会出现错误:

class CritLevel (models.IntegerChoices): AttributeError: module 'django.db.models' has no attribute 'IntegerChoices'

模型中的我的代码:

import uuid

from common.models import CommonPermissionSet

from django.core.validators import MinValueValidator

from django.db import models

from django.utils.translation import gettext_lazy as _

from. import managers

class CritLevel (models.IntegerChoices):
     LOW = 1, _ ('Low')
     MEDIUM = 2, _ ('Medium')
     HIGH = 3, _ ('High')

class TypeElHw (models.IntegerChoices):
     EL = 1, _ ('Electrical Energy')
     HW = 2, _ ('Heat energy')

class OrganizationType (models.IntegerChoices):
     EPO = 1, _ ('EPO')
     ESO = 2, _ ('ESO')

Tags: djangofromimportdbmodels错误classattributeerror