gpt4 book ai didi

python - 选择必须是可迭代的

转载 作者:太空宇宙 更新时间:2023-11-03 13:39:56 26 4
gpt4 key购买 nike

我在使用 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]

最佳答案

你必须在''中设置值

STATUS_CHOICES = (
('d', 'Draft'),
('p', 'Published'),
)

关于python - 选择必须是可迭代的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33326999/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com