我在几个月前已经问过这个问题。
问题是愚蠢的,但我不能找到解决方案。什么是有效的格式,节省嵌套数组的时间从简单的形式文本字段?
我有这样的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”,但它不工作。
2条答案
按热度按时间wrrgggsh1#
您的
schedule
字段是一个三维数组,但您传递的是一个二维数组。schedule
字段定义应为:字符串
另外,默认的Django小部件不支持嵌套数组。你必须创建自己的小部件。
rjee0c152#
在@antoine-pinsard回答的最后,我补充一句,不可能像Array(Array(SomeSimpleField))那样保存字段-因为django的
from django.contrib.postgres.forms import SimpleArrayField
表单不允许这样做。所以解决方案很简单-我已经创建了自己的根ArrayField并将数组的数组名指定为
;
:字符串
现在我可以像这样填充字段:
12.33, 43,12; 334.54, 12.4