当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python Django SplitArrayField.remove_trailing_nulls用法及代码示例


本文介绍django.contrib.postgres.forms.SplitArrayField.remove_trailing_nulls的用法。

声明

remove_trailing_nulls

默认情况下,这设置为 False 。当 False 时,存储来自重复字段的每个值。当设置为 True 时,任何空白的尾随值都将从结果中删除。如果基础字段具有 required=True ,但 remove_trailing_nullsTrue ,则空值仅允许在末尾,并将被剥离。

一些例子:

SplitArrayField(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]

相关用法


注:本文由纯净天空筛选整理自djangoproject.com大神的英文原创作品 django.contrib.postgres.forms.SplitArrayField.remove_trailing_nulls。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。