Arrayfield in Django
10,458
In your case you are talking about 1-dim
array, and it should be smth like that:
board = ArrayField(
ArrayField(
models.CharField(max_length=10, blank=True),
size=8,
),
size=1,
)
so in your case smth like:
pagerange_str_array = ArrayField(
ArrayField(
models.CharField(max_length=10, blank=True)
),
size=1
)
Author by
Malik A. Rumi
Updated on June 04, 2022Comments
-
Malik A. Rumi almost 2 years
my code:
pagerange_str_array = ArrayField(models.CharField(max_length=10, blank=True, default=list()))
docs example: https://docs.djangoproject.com/en/2.0/ref/contrib/postgres/fields/
board = ArrayField( ArrayField( models.CharField(max_length=10, blank=True), size=8, ), size=8, )
docs - size: This is an optional argument.
error message:
DETAIL: Array value must start with "{" or dimension information.
But none of these work: default={}, '{}',or {''} They all get the same error message.
docs: If you give the field a default, ensure it’s a callable such as list (for an empty default) or a callable that returns a list (such as a function)
But none of these work either: default=list, list(). null=True (my original code) also does not work.
All these examples give the same error. I have seen non-Django solutions on the web, but what is an example of code that works in Django?! Thanks.
-
Paulo Almeida about 6 yearsThis is probably not the issue, but your
default
is in theCharField
, not in theArrayField
. -
Malik A. Rumi about 6 yearsI've never seen it done that way, but perhaps a good tip. Thanks.
-
-
Malik A. Rumi about 6 yearsOk, that makes sense. I thought if there was nothing there about size, then by default the dimensions would match.