[英]Choices must be iterable
I am having an issue with Django and Python我在使用 Django 和 Python 时遇到问题
I am facing the error .from_hour: (fields.E005) 'choices' must be an iterable containing (actual value, human readable name) tuples.
我正面临错误.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我知道如果我评论from_hour
和to_hour
它会运行
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]
you must set values in ''您必须在 '' 中设置值
STATUS_CHOICES = (
('d', 'Draft'),
('p', 'Published'),
)
The error is related to from_hour
.该错误与from_hour
相关。 You should provide a collection of tuples like from_hour = models.IntegerField(choices=[(x, str(x)) for x in range(1,25)])
.您应该提供一组元组,例如from_hour = models.IntegerField(choices=[(x, str(x)) for x in range(1,25)])
。 And I think you should do the same for the to_hour
field.我认为你应该对to_hour
字段做同样的to_hour
。
you must use WEEKDAYS.choices in choices attr, change this line:您必须在选择属性中使用WEEKDAYS.choices ,更改这一行:
weekday_from = models.IntegerField(choices=WEEKDAYS, unique=True)
to到
weekday_from = models.IntegerField(choices=WEEKDAYS.choices, unique=True)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.