class SplitArrayField(base_field, size, remove_trailing_nulls=False)
[source]
This field handles arrays by reproducing the underlying field a fixed number of times.
-
base_field
-
This is a required argument. It specifies the form field to be repeated.
-
size
-
This is the fixed number of times the underlying field will be used.
-
remove_trailing_nulls
-
By default, this is set to
False
. WhenFalse
, each value from the repeated fields is stored. When set toTrue
, any trailing values which are blank will be stripped from the result. If the underlying field hasrequired=True
, butremove_trailing_nulls
isTrue
, then null values are only allowed at the end, and will be stripped.Some examples:
123456789101112131415161718192021222324252627SplitArrayField(IntegerField(required
=
True
), size
=
3
, remove_trailing_nulls
=
False
)
[
'1'
,
'2'
,
'3'
]
# -> [1, 2, 3]
[
'1'
,
'2'
, '']
# -> ValidationError - third entry required.
[
'1'
, '
', '
3
']
# -> ValidationError - second entry required.
['
', '
2
', '
']
# -> ValidationError - first and third entries required.
SplitArrayField(IntegerField(required
=
False
), size
=
3
, remove_trailing_nulls
=
False
)
[
'1'
,
'2'
,
'3'
]
# -> [1, 2, 3]
[
'1'
,
'2'
, '']
# -> [1, 2, None]
[
'1'
, '
', '
3
']
# -> [1, None, 3]
['
', '
2
', '
']
# -> [None, 2, None]
SplitArrayField(IntegerField(required
=
True
), size
=
3
, remove_trailing_nulls
=
True
)
[
'1'
,
'2'
,
'3'
]
# -> [1, 2, 3]
[
'1'
,
'2'
, '']
# -> [1, 2]
[
'1'
, '
', '
3
']
# -> ValidationError - second entry required.
['
', '
2
', '
']
# -> ValidationError - first entry required.
SplitArrayField(IntegerField(required
=
False
), size
=
3
, remove_trailing_nulls
=
True
)
[
'1'
,
'2'
,
'3'
]
# -> [1, 2, 3]
[
'1'
,
'2'
, '']
# -> [1, 2]
[
'1'
, '
', '
3
']
# -> [1, None, 3]
['
', '
2
', '
']
# -> [None, 2]
Please login to continue.