當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。