Django 数组字段。如何通过 django admin 保存嵌套的时间数组?

Django ArrayField. How to save nested array of time through django admin?

几个月前我已经问过这个问题了。

问题很愚蠢,但我找不到解决方案。从简单表单文本字段中保存嵌套时间数组的有效格式是什么?

我有这样的 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" 但没有成功。

您的 schedule 字段是一个 3 维数组,但您传递的是一个 2 维数组。

schedule 字段定义应该是:

schedule = ArrayField(
    ArrayField(
        models.TimeField(null=True),
        size=2,
        null=True,
    ),
    size=7,
    null=True,
    blank=True,
)

此外,默认的 Django 小部件不支持嵌套数组。您将必须创建自己的小部件。