Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Choices must be iterable

Tags:

python

django

I am having an issue with Django and Python

I am facing the error .from_hour: (fields.E005) 'choices' must be an iterable containing (actual value, human readable name) tuples. Can someone help me understand what the error is? I know if I comment from_hour and to_hour it runs

Here is my code

WEEKDAYS = [
  (1, _("Monday")),
  (2, _("Tuesday")),
  (3, _("Wednesday")),
  (4, _("Thursday")),
  (5, _("Friday")),
  (6, _("Saturday")),
  (7, _("Sunday")),
]


weekday_from = models.IntegerField(choices=WEEKDAYS, unique=True)
weekday_to = models.IntegerField(choices=WEEKDAYS)
from_hour = models.IntegerField(choices=range(1,25))
to_hour = models.IntegerField(choices=range(1,25))

def get_weekday_from_display(self):
    return WEEKDAYS[self.weekday_from]

def get_weekday_to_display(self):
    return WEEKDAYS[self.weekday_to]
like image 341
PictureMeAndYou Avatar asked Oct 25 '15 06:10

PictureMeAndYou


2 Answers

you must use WEEKDAYS.choices in choices attr, change this line:

weekday_from = models.IntegerField(choices=WEEKDAYS, unique=True)

to

weekday_from = models.IntegerField(choices=WEEKDAYS.choices, unique=True)
like image 135
hassanzadeh.sd Avatar answered Sep 21 '22 01:09

hassanzadeh.sd


you must set values in ''

STATUS_CHOICES = (
    ('d', 'Draft'),
    ('p', 'Published'),
)
like image 26
Mohammad Hossein Gerami Avatar answered Sep 21 '22 01:09

Mohammad Hossein Gerami