我尝试使用django_enums并在进行迁移时遇到 list(cls)错误:
(venv:SFS)rita@rita-notebook:~/Serpentarium/ServiceForServices/project/serviceforservices$ python manage.py makemigrations
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/rita/Serpentarium/ServiceForServices/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/home/rita/Serpentarium/ServiceForServices/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 341, in execute
django.setup()
File "/home/rita/Serpentarium/ServiceForServices/venv/local/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/rita/Serpentarium/ServiceForServices/venv/local/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/home/rita/Serpentarium/ServiceForServices/venv/local/lib/python2.7/site-packages/django/apps/config.py", line 199, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/rita/Serpentarium/ServiceForServices/project/serviceforservices/service/models.py", line 84, in <module>
class EmployeesStatus(models.Model):
File "/home/rita/Serpentarium/ServiceForServices/project/serviceforservices/service/models.py", line 86, in EmployeesStatus
status = enum.EnumField(StatusEnum, default=StatusEnum.AT)
File "/home/rita/Serpentarium/ServiceForServices/venv/local/lib/python2.7/site-packages/django_enums/enum.py", line 53, in __init__
kwargs['max_length'] = self.enum.get_max_length()
File "/home/rita/Serpentarium/ServiceForServices/venv/local/lib/python2.7/site-packages/django_enums/enum.py", line 39, in get_max_length
return len(max(list(cls), key=(lambda x: len(x.key))).key)
TypeError: 'type' object is not iterable
我安装了django-enums,enum和six:
(venv:SFS)rita@rita-notebook:~/Serpentarium/ServiceForServices/project/serviceforservices$ pip install django-enums
(venv:SFS)rita@rita-notebook:~/Serpentarium/ServiceForServices/project/serviceforservices$ pip install enum
(venv:SFS)rita@rita-notebook:~/Serpentarium/ServiceForServices/project/serviceforservices$ pip install six
在Models.py中使用:
...
from django_enums import enum
...
class StatusEnum(enum.Enum):
__order__ = 'AT BT BC AC' # for python 2
AT = (u'АВ', u'Активен временно')
BT = (u'БВ', u'Блокирован временно')
BC = (u'БП', u'Блокирован постоянно')
AC = (u'АП', u'Активен постоянно')
class EmployeesStatus(models.Model):
name = models.CharField(max_length=128)
status = enum.EnumField(StatusEnum, default=StatusEnum.AT)
似乎项目还活着,它也被更新为Django 1.10并据称与python 2分开。那么,我做错了什么?
答案 0 :(得分:1)
看起来您正在尝试使用3.4 stdlib中的反向移植枚举,但是您安装了enum
- 您需要安装enum34
。