选择必须是可迭代的

Pic*_*You 10 python django

我在使用 Django 和 Python 时遇到问题

我正面临错误.from_hour: (fields.E005) 'choices' must be an iterable containing (actual value, human readable name) tuples.有人可以帮助我了解错误是什么吗?我知道我是否发表评论from_hourto_hour运行

这是我的代码

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]
Run Code Online (Sandbox Code Playgroud)

Moh*_*ami 7

您必须在 '' 中设置值

STATUS_CHOICES = (
    ('d', 'Draft'),
    ('p', 'Published'),
)
Run Code Online (Sandbox Code Playgroud)