Reputation: 43
I tried to use django_enums and got an error with list(cls) when making migrations:
(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
I installed django-enums, enum and 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
Using in 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)
It seems like project is alive, it also was updated for Django 1.10 and compartible with python 2 allegedly. So, what I'm doing wrong?
Upvotes: 4
Views: 899
Reputation: 69110
It looks like you are trying to use the backported enum from the 3.4 stdlib, but you installed enum
-- you need to install enum34
.
Upvotes: 2