几个月前我已经问过这个问题了。
问题很愚蠢,但我无法找到解决方案。从简单表单文本字段保存嵌套时间数组的有效格式是什么?
我有这样的ArrayField:
schedule = ArrayField(
ArrayField(
ArrayField(
models.TimeField(null=True),
),
size=2,
null=True,
),
size=7,
null=True,
blank=True,
)
当我试图从django admin保存它时:
((09:00, 09:00), (09:00, 09:00), (09:00, 09:00), (09:00, 09:00), (09:00, 9:00), (9:00, 9:00), (9:00, 9:00))
我收到错误
Item 0 in the array did not validate: Item 0 in the array did not validate: Item 0 in the array did not validate: Enter a valid time.
Item 1 in the array did not validate: Item 0 in the array did not validate: Item 0 in the array did not validate: Enter a valid time.
Item 2 in the array did not validate: Item 0 in the array did not validate: Item 0 in the array did not validate: Enter a valid time.
Item 3 in the array did not validate: Item 0 in the array did not validate: Item 0 in the array did not validate: Enter a valid time.
Item 4 in the array did not validate: Item 0 in the array did not validate: Item 0 in the array did not validate: Enter a valid time.
Item 5 in the array did not validate: Item 0 in the array did not validate: Item 0 in the array did not validate: Enter a valid time.
Item 6 in the array did not validate: Item 0 in the array did not validate: Item 0 in the array did not validate: Enter a valid time.
Item 7 in the array did not validate: Item 0 in the array did not validate: Item 0 in the array did not validate: Enter a valid time.
Item 8 in the array did not validate: Item 0 in the array did not validate: Item 0 in the array did not validate: Enter a valid time.
Item 9 in the array did not validate: Item 0 in the array did not validate: Item 0 in the array did not validate: Enter a valid time.
Item 10 in the array did not validate: Item 0 in the array did not validate: Item 0 in the array did not validate: Enter a valid time.
Item 11 in the array did not validate: Item 0 in the array did not validate: Item 0 in the array did not validate: Enter a valid time.
Item 12 in the array did not validate: Item 0 in the array did not validate: Item 0 in the array did not validate: Enter a valid time.
Item 13 in the array did not validate: Item 0 in the array did not validate: Item 0 in the array did not validate: Enter a valid time.
我已经尝试了其他一些格式,例如:[[“09:00”,“09:00”]]或(('09:00','09:00'))或只是像“09:”这样的纯文本: 00“,”09:00“但它没有用。
答案 0 :(得分:1)
您的schedule
字段是一个三维数组,但您传递的是二维数组。
schedule
字段定义应为:
schedule = ArrayField(
ArrayField(
models.TimeField(null=True),
size=2,
null=True,
),
size=7,
null=True,
blank=True,
)
此外,默认的Django小部件不支持嵌套数组。您必须创建自己的小部件。