0
DjangoモデルでPython 3.5でEnumを使用しようとしています。移行しようとしているときに、なぜこれを取得していますか?DjangoモデルでEnum(Python 3.5)を使用した場合のAttributeError
field=models.CharField(choices=[('RE', 'Red'), ('GR', 'Green'), ('BL', 'Blue'), ('OR', 'Orange'), ('YE', 'Yellow'), ('PU', 'Purple')], default=users.models.COLOR('BL'), max_length=2),
AttributeError: module 'users.models' has no attribute 'COLOR'
-
class User(AbstractBaseUser):
class COLOR(enum.Enum):
RED = 'RE'
GREEN = 'GR'
BLUE = 'BL'
ORANGE = 'OR'
YELLOW = 'YE'
PURPLE = 'PU'
//...
color = models.CharField(max_length=2, choices=((x.value, x.name.title()) for x in COLOR), default=COLOR.BLUE)
3.4と3.5は異なるバージョンです。 – user2357112
@ user2357112これはタイプミスですが、私はPython 3.5を使用しています – arooo
https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.Field.choices 。 – wencakisa