“Django/docs/3.0.x/ref/contrib/postgres/forms”的版本间差异
(autoload) |
小 (Page commit) |
||
第1行: | 第1行: | ||
+ | {{DISPLAYTITLE:PostgreSQL 特定的表单域和小部件 — Django 文档}} | ||
<div id="postgresql-specific-form-fields-and-widgets" class="section"> | <div id="postgresql-specific-form-fields-and-widgets" class="section"> | ||
− | = PostgreSQL | + | = PostgreSQL 特定的表单字段和小部件 = |
− | + | 所有这些字段和小部件都可以从 <code>django.contrib.postgres.forms</code> 模块获得。 | |
− | <code>django.contrib.postgres.forms</code> | ||
<div id="fields" class="section"> | <div id="fields" class="section"> | ||
第12行: | 第12行: | ||
<div id="simplearrayfield" class="section"> | <div id="simplearrayfield" class="section"> | ||
− | === | + | === SimpleArrayField === |
<dl> | <dl> | ||
− | <dt>''class'' < | + | <dt>''<span class="pre">class</span>'' <span class="sig-name descname"><span class="pre">SimpleArrayField</span></span><span class="sig-paren">(</span>''<span class="n"><span class="pre">base_field</span></span>'', ''<span class="n"><span class="pre">delimiter</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">','</span></span>'', ''<span class="n"><span class="pre">max_length</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span>'', ''<span class="n"><span class="pre">min_length</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span>''<span class="sig-paren">)</span></dt> |
− | <dd><p> | + | <dd><p>映射到数组的字段。 它由 HTML <code><input></code> 表示。</p> |
<dl> | <dl> | ||
− | <dt>< | + | <dt><span class="sig-name descname"><span class="pre">base_field</span></span></dt> |
− | <dd><p> | + | <dd><p>这是一个必需的参数。</p> |
− | <p> | + | <p>它指定数组的底层表单字段。 这不用于呈现任何 HTML,但用于处理提交的数据并对其进行验证。 例如:</p> |
− | |||
− | |||
<div class="highlight-default notranslate"> | <div class="highlight-default notranslate"> | ||
<div class="highlight"> | <div class="highlight"> | ||
− | < | + | <syntaxhighlight lang="python">>>> from django import forms |
− | + | >>> from django.contrib.postgres.forms import SimpleArrayField | |
− | + | >>> class NumberListForm(forms.Form): | |
... numbers = SimpleArrayField(forms.IntegerField()) | ... numbers = SimpleArrayField(forms.IntegerField()) | ||
− | + | >>> form = NumberListForm({'numbers': '1,2,3'}) | |
− | + | >>> form.is_valid() | |
True | True | ||
− | + | >>> form.cleaned_data | |
{'numbers': [1, 2, 3]} | {'numbers': [1, 2, 3]} | ||
− | + | >>> form = NumberListForm({'numbers': '1,2,a'}) | |
− | + | >>> form.is_valid() | |
− | False</ | + | False</syntaxhighlight> |
</div> | </div> | ||
第48行: | 第46行: | ||
<dl> | <dl> | ||
− | <dt>< | + | <dt><span class="sig-name descname"><span class="pre">delimiter</span></span></dt> |
− | <dd><p> | + | <dd><p>这是一个可选参数,默认为逗号:<code>,</code>。 该值用于拆分提交的数据。 它允许您为多维数据链接 <code>SimpleArrayField</code>:</p> |
− | |||
− | <code>SimpleArrayField</code> | ||
<div class="highlight-default notranslate"> | <div class="highlight-default notranslate"> | ||
<div class="highlight"> | <div class="highlight"> | ||
− | < | + | <syntaxhighlight lang="python">>>> from django import forms |
− | + | >>> from django.contrib.postgres.forms import SimpleArrayField | |
− | + | >>> class GridForm(forms.Form): | |
... places = SimpleArrayField(SimpleArrayField(IntegerField()), delimiter='|') | ... places = SimpleArrayField(SimpleArrayField(IntegerField()), delimiter='|') | ||
− | + | >>> form = GridForm({'places': '1,2|2,1|4,3'}) | |
− | + | >>> form.is_valid() | |
True | True | ||
− | + | >>> form.cleaned_data | |
− | {'places': [[1, 2], [2, 1], [4, 3]]}</ | + | {'places': [[1, 2], [2, 1], [4, 3]]}</syntaxhighlight> |
</div> | </div> | ||
第73行: | 第69行: | ||
<div class="admonition note"> | <div class="admonition note"> | ||
− | <p> | + | <p>笔记</p> |
− | <p> | + | <p>该字段不支持对分隔符进行转义,因此在分隔符是基础字段中的有效字符的情况下要小心。 分隔符不必只有一个字符。</p> |
− | |||
− | |||
</div></dd></dl> | </div></dd></dl> | ||
<dl> | <dl> | ||
− | <dt>< | + | <dt><span class="sig-name descname"><span class="pre">max_length</span></span></dt> |
− | <dd><p> | + | <dd><p>这是一个可选参数,用于验证数组不超过规定的长度。</p></dd></dl> |
− | |||
<dl> | <dl> | ||
− | <dt>< | + | <dt><span class="sig-name descname"><span class="pre">min_length</span></span></dt> |
− | <dd><p> | + | <dd><p>这是一个可选参数,用于验证数组是否至少达到了规定的长度。</p></dd></dl> |
− | |||
<div class="admonition-user-friendly-forms admonition"> | <div class="admonition-user-friendly-forms admonition"> | ||
− | <p> | + | <p>用户友好的表格</p> |
− | <p><code>SimpleArrayField</code> | + | <p><code>SimpleArrayField</code> 在大多数情况下不是特别用户友好,但它是一种有用的方式来格式化来自客户端小部件的数据以提交到服务器。</p> |
− | |||
− | |||
</div></dd></dl> | </div></dd></dl> | ||
第103行: | 第93行: | ||
<div id="splitarrayfield" class="section"> | <div id="splitarrayfield" class="section"> | ||
− | === | + | === SplitArrayField === |
<dl> | <dl> | ||
− | <dt>''class'' < | + | <dt>''<span class="pre">class</span>'' <span class="sig-name descname"><span class="pre">SplitArrayField</span></span><span class="sig-paren">(</span>''<span class="n"><span class="pre">base_field</span></span>'', ''<span class="n"><span class="pre">size</span></span>'', ''<span class="n"><span class="pre">remove_trailing_nulls</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span>''<span class="sig-paren">)</span></dt> |
− | <dd><p> | + | <dd><p>该字段通过将基础字段复制固定次数来处理数组。</p> |
− | |||
<dl> | <dl> | ||
− | <dt>< | + | <dt><span class="sig-name descname"><span class="pre">base_field</span></span></dt> |
− | <dd><p> | + | <dd><p>这是一个必需的参数。 它指定要重复的表单字段。</p></dd></dl> |
− | |||
<dl> | <dl> | ||
− | <dt>< | + | <dt><span class="sig-name descname"><span class="pre">size</span></span></dt> |
− | <dd><p> | + | <dd><p>这是基础字段将被使用的固定次数。</p></dd></dl> |
<dl> | <dl> | ||
− | <dt>< | + | <dt><span class="sig-name descname"><span class="pre">remove_trailing_nulls</span></span></dt> |
− | <dd><p> | + | <dd><p>默认情况下,它设置为 <code>False</code>。 当 <code>False</code> 时,存储重复字段中的每个值。 当设置为 <code>True</code> 时,任何空白的尾随值都将从结果中删除。 如果底层字段有 <code>required=True</code>,但 <code>remove_trailing_nulls</code> 是 <code>True</code>,那么最后只允许空值,将被剥离。</p> |
− | + | <p>一些例子:</p> | |
− | |||
− | |||
− | |||
− | |||
− | <p> | ||
<div class="highlight-default notranslate"> | <div class="highlight-default notranslate"> | ||
<div class="highlight"> | <div class="highlight"> | ||
− | < | + | <syntaxhighlight lang="python">SplitArrayField(IntegerField(required=True), size=3, remove_trailing_nulls=False) |
− | ['1', '2', '3'] # - | + | ['1', '2', '3'] # -> [1, 2, 3] |
− | ['1', '2', ''] # - | + | ['1', '2', ''] # -> ValidationError - third entry required. |
− | ['1', '', '3'] # - | + | ['1', '', '3'] # -> ValidationError - second entry required. |
− | ['', '2', ''] # - | + | ['', '2', ''] # -> ValidationError - first and third entries required. |
SplitArrayField(IntegerField(required=False), size=3, remove_trailing_nulls=False) | SplitArrayField(IntegerField(required=False), size=3, remove_trailing_nulls=False) | ||
− | ['1', '2', '3'] # - | + | ['1', '2', '3'] # -> [1, 2, 3] |
− | ['1', '2', ''] # - | + | ['1', '2', ''] # -> [1, 2, None] |
− | ['1', '', '3'] # - | + | ['1', '', '3'] # -> [1, None, 3] |
− | ['', '2', ''] # - | + | ['', '2', ''] # -> [None, 2, None] |
SplitArrayField(IntegerField(required=True), size=3, remove_trailing_nulls=True) | SplitArrayField(IntegerField(required=True), size=3, remove_trailing_nulls=True) | ||
− | ['1', '2', '3'] # - | + | ['1', '2', '3'] # -> [1, 2, 3] |
− | ['1', '2', ''] # - | + | ['1', '2', ''] # -> [1, 2] |
− | ['1', '', '3'] # - | + | ['1', '', '3'] # -> ValidationError - second entry required. |
− | ['', '2', ''] # - | + | ['', '2', ''] # -> ValidationError - first entry required. |
SplitArrayField(IntegerField(required=False), size=3, remove_trailing_nulls=True) | SplitArrayField(IntegerField(required=False), size=3, remove_trailing_nulls=True) | ||
− | ['1', '2', '3'] # - | + | ['1', '2', '3'] # -> [1, 2, 3] |
− | ['1', '2', ''] # - | + | ['1', '2', ''] # -> [1, 2] |
− | ['1', '', '3'] # - | + | ['1', '', '3'] # -> [1, None, 3] |
− | ['', '2', ''] # - | + | ['', '2', ''] # -> [None, 2]</syntaxhighlight> |
</div> | </div> | ||
第168行: | 第151行: | ||
<div id="hstorefield" class="section"> | <div id="hstorefield" class="section"> | ||
− | === | + | === HStoreField === |
<dl> | <dl> | ||
− | <dt>''class'' < | + | <dt>''<span class="pre">class</span>'' <span class="sig-name descname"><span class="pre">HStoreField</span></span></dt> |
− | <dd><p> | + | <dd><p>接受 [[../fields#django.contrib.postgres.fields|HStoreField]] 的 JSON 编码数据的字段。 它将所有值(空值除外)转换为字符串。 它由 HTML <code><textarea></code> 表示。</p> |
− | [[../fields#django.contrib.postgres.fields| | ||
− | |||
<div class="admonition-user-friendly-forms admonition"> | <div class="admonition-user-friendly-forms admonition"> | ||
− | <p> | + | <p>用户友好的表格</p> |
− | <p><code>HStoreField</code> | + | <p><code>HStoreField</code> 在大多数情况下不是特别用户友好,但它是一种有用的方式来格式化来自客户端小部件的数据以提交到服务器。</p> |
− | |||
− | |||
</div> | </div> | ||
<div class="admonition note"> | <div class="admonition note"> | ||
− | <p> | + | <p>笔记</p> |
− | <p> | + | <p>有时,要求或限制对给定字段有效的键可能很有用。 这可以使用 [[../validators#django.contrib.postgres.validators|KeysValidator]] 来完成。</p> |
− | |||
− | [[../validators#django.contrib.postgres.validators| | ||
</div></dd></dl> | </div></dd></dl> | ||
第196行: | 第173行: | ||
<div id="jsonfield" class="section"> | <div id="jsonfield" class="section"> | ||
− | === | + | === JSONField === |
<dl> | <dl> | ||
− | <dt>''class'' < | + | <dt>''<span class="pre">class</span>'' <span class="sig-name descname"><span class="pre">JSONField</span></span></dt> |
− | <dd><p> | + | <dd><p>接受 [[../fields#django.contrib.postgres.fields|JSONField]] 的 JSON 编码数据的字段。 它由 HTML <code><textarea></code> 表示。</p> |
− | [[../fields#django.contrib.postgres.fields| | ||
− | HTML <code><textarea></code> | ||
<div class="admonition-user-friendly-forms admonition"> | <div class="admonition-user-friendly-forms admonition"> | ||
− | <p> | + | <p>用户友好的表格</p> |
− | <p><code>JSONField</code> | + | <p><code>JSONField</code> 在大多数情况下不是特别用户友好,但它是一种有用的方式来格式化来自客户端小部件的数据以提交到服务器。</p> |
− | |||
− | |||
</div></dd></dl> | </div></dd></dl> | ||
第216行: | 第189行: | ||
<div id="range-fields" class="section"> | <div id="range-fields" class="section"> | ||
− | === | + | === 范围字段 === |
− | + | 这组字段都共享用于接受范围数据的相似功能。 它们基于 [[../../../forms/fields#django.forms|MultiValueField]]。 他们将一个省略的值视为一个无界范围。 他们还验证下限不大于上限。 所有这些字段都使用 [[#django.contrib.postgres.forms.RangeWidget|RangeWidget]]。 | |
− | |||
− | |||
− | |||
− | [[#django.contrib.postgres.forms.RangeWidget| | ||
<div id="integerrangefield" class="section"> | <div id="integerrangefield" class="section"> | ||
− | ==== | + | ==== IntegerRangeField ==== |
− | ; ''class'' < | + | ; ''<span class="pre">class</span>'' <span class="sig-name descname"><span class="pre">IntegerRangeField</span></span> |
− | : | + | : 基于 [[../../../forms/fields#django.forms|IntegerField]] 并将其输入转换为 <code>NumericRange</code>。 [[../fields#django.contrib.postgres.fields|IntegerRangeField]] 和 [[../fields#django.contrib.postgres.fields|BigIntegerRangeField]] 的默认值。 |
第235行: | 第204行: | ||
<div id="decimalrangefield" class="section"> | <div id="decimalrangefield" class="section"> | ||
− | ==== | + | ==== DecimalRangeField ==== |
<dl> | <dl> | ||
− | <dt>''class'' < | + | <dt>''<span class="pre">class</span>'' <span class="sig-name descname"><span class="pre">DecimalRangeField</span></span></dt> |
<dd><div class="versionadded"> | <dd><div class="versionadded"> | ||
− | + | <p><span class="versionmodified added">2.2 版中的新功能。</span></p> | |
</div> | </div> | ||
− | <p> | + | <p>基于 [[../../../forms/fields#django.forms|DecimalField]] 并将其输入转换为 <code>NumericRange</code>。 [[../fields#django.contrib.postgres.fields|DecimalRangeField]] 的默认值。</p></dd></dl> |
− | <code>NumericRange</code> | ||
− | [[../fields#django.contrib.postgres.fields| | ||
第252行: | 第219行: | ||
<div id="floatrangefield" class="section"> | <div id="floatrangefield" class="section"> | ||
− | ==== | + | ==== FloatRangeField ==== |
<dl> | <dl> | ||
− | <dt>''class'' < | + | <dt>''<span class="pre">class</span>'' <span class="sig-name descname"><span class="pre">FloatRangeField</span></span></dt> |
− | <dd><p> | + | <dd><p>基于 [[../../../forms/fields#django.forms|FloatField]] 并将其输入转换为 <code>NumericRange</code>。 [[../fields#django.contrib.postgres.fields|FloatRangeField]] 的默认值。</p> |
− | <code>NumericRange</code> | ||
− | [[../fields#django.contrib.postgres.fields| | ||
<div class="deprecated"> | <div class="deprecated"> | ||
− | <p><span class="versionmodified deprecated">2.2 | + | <p><span class="versionmodified deprecated"> 自 2.2 版起已弃用:</span> 改用 [[#django.contrib.postgres.forms.DecimalRangeField|DecimalRangeField]]。</p> |
</div></dd></dl> | </div></dd></dl> | ||
第269行: | 第234行: | ||
<div id="datetimerangefield" class="section"> | <div id="datetimerangefield" class="section"> | ||
− | ==== | + | ==== DateTimeRangeField ==== |
− | ; ''class'' < | + | ; ''<span class="pre">class</span>'' <span class="sig-name descname"><span class="pre">DateTimeRangeField</span></span> |
− | : | + | : 基于 [[../../../forms/fields#django.forms|DateTimeField]] 并将其输入转换为 <code>DateTimeTZRange</code>。 [[../fields#django.contrib.postgres.fields|DateTimeRangeField]] 的默认值。 |
第278行: | 第243行: | ||
<div id="daterangefield" class="section"> | <div id="daterangefield" class="section"> | ||
− | ==== | + | ==== DateRangeField ==== |
− | ; ''class'' < | + | ; ''<span class="pre">class</span>'' <span class="sig-name descname"><span class="pre">DateRangeField</span></span> |
− | : | + | : 基于 [[../../../forms/fields#django.forms|DateField]] 并将其输入转换为 <code>DateRange</code>。 [[../fields#django.contrib.postgres.fields|DateRangeField]] 的默认值。 |
第291行: | 第256行: | ||
<div id="widgets" class="section"> | <div id="widgets" class="section"> | ||
− | == | + | == 小工具 == |
<div id="rangewidget" class="section"> | <div id="rangewidget" class="section"> | ||
− | === | + | === RangeWidget === |
<dl> | <dl> | ||
− | <dt>''class'' < | + | <dt>''<span class="pre">class</span>'' <span class="sig-name descname"><span class="pre">RangeWidget</span></span><span class="sig-paren">(</span>''<span class="n"><span class="pre">base_widget</span></span>'', ''<span class="n"><span class="pre">attrs</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span>''<span class="sig-paren">)</span></dt> |
− | <dd><p> | + | <dd><p>所有范围字段使用的小部件。 基于 [[../../../forms/widgets#django.forms|MultiWidget]]。</p> |
− | + | <p>[[#django.contrib.postgres.forms.RangeWidget|RangeWidget]] 有一个必需的参数:</p> | |
− | <p>[[#django.contrib.postgres.forms.RangeWidget| | ||
<dl> | <dl> | ||
− | <dt>< | + | <dt><span class="sig-name descname"><span class="pre">base_widget</span></span></dt> |
− | <dd><p> | + | <dd><p>[[#django.contrib.postgres.forms.RangeWidget|RangeWidget]] 包含 <code>base_widget</code> 的 2 元组。</p></dd></dl> |
<dl> | <dl> | ||
− | <dt>< | + | <dt><span class="sig-name descname"><span class="pre">decompress</span></span><span class="sig-paren">(</span>''<span class="n"><span class="pre">value</span></span>''<span class="sig-paren">)</span></dt> |
− | <dd><p> | + | <dd><p>获取字段的单个“压缩”值,例如 [[../fields#django.contrib.postgres.fields|DateRangeField]],并返回表示下限和上限的元组。</p></dd></dl> |
− | [[../fields#django.contrib.postgres.fields| | ||
− | |||
</dd></dl> | </dd></dl> | ||
第317行: | 第279行: | ||
</div> | </div> | ||
+ | |||
+ | </div> | ||
+ | <div class="clearer"> | ||
+ | |||
+ | |||
</div> | </div> | ||
− | [[Category:Django 3.0.x | + | [[Category:Django 3.0.x 文档]] |
2021年10月31日 (日) 04:09的最新版本
PostgreSQL 特定的表单字段和小部件
所有这些字段和小部件都可以从 django.contrib.postgres.forms
模块获得。
字段
SimpleArrayField
- class SimpleArrayField(base_field, delimiter=',', max_length=None, min_length=None)
映射到数组的字段。 它由 HTML
<input>
表示。- base_field
这是一个必需的参数。
它指定数组的底层表单字段。 这不用于呈现任何 HTML,但用于处理提交的数据并对其进行验证。 例如:
>>> from django import forms >>> from django.contrib.postgres.forms import SimpleArrayField >>> class NumberListForm(forms.Form): ... numbers = SimpleArrayField(forms.IntegerField()) >>> form = NumberListForm({'numbers': '1,2,3'}) >>> form.is_valid() True >>> form.cleaned_data {'numbers': [1, 2, 3]} >>> form = NumberListForm({'numbers': '1,2,a'}) >>> form.is_valid() False
- delimiter
这是一个可选参数,默认为逗号:
,
。 该值用于拆分提交的数据。 它允许您为多维数据链接SimpleArrayField
:>>> from django import forms >>> from django.contrib.postgres.forms import SimpleArrayField >>> class GridForm(forms.Form): ... places = SimpleArrayField(SimpleArrayField(IntegerField()), delimiter='|') >>> form = GridForm({'places': '1,2|2,1|4,3'}) >>> form.is_valid() True >>> form.cleaned_data {'places': [[1, 2], [2, 1], [4, 3]]}
笔记
该字段不支持对分隔符进行转义,因此在分隔符是基础字段中的有效字符的情况下要小心。 分隔符不必只有一个字符。
- max_length
这是一个可选参数,用于验证数组不超过规定的长度。
- min_length
这是一个可选参数,用于验证数组是否至少达到了规定的长度。
用户友好的表格
SimpleArrayField
在大多数情况下不是特别用户友好,但它是一种有用的方式来格式化来自客户端小部件的数据以提交到服务器。
SplitArrayField
- class SplitArrayField(base_field, size, remove_trailing_nulls=False)
该字段通过将基础字段复制固定次数来处理数组。
- base_field
这是一个必需的参数。 它指定要重复的表单字段。
- size
这是基础字段将被使用的固定次数。
- remove_trailing_nulls
默认情况下,它设置为
False
。 当False
时,存储重复字段中的每个值。 当设置为True
时,任何空白的尾随值都将从结果中删除。 如果底层字段有required=True
,但remove_trailing_nulls
是True
,那么最后只允许空值,将被剥离。一些例子:
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]
HStoreField
- class HStoreField
接受 HStoreField 的 JSON 编码数据的字段。 它将所有值(空值除外)转换为字符串。 它由 HTML
<textarea>
表示。用户友好的表格
HStoreField
在大多数情况下不是特别用户友好,但它是一种有用的方式来格式化来自客户端小部件的数据以提交到服务器。笔记
有时,要求或限制对给定字段有效的键可能很有用。 这可以使用 KeysValidator 来完成。
JSONField
- class JSONField
接受 JSONField 的 JSON 编码数据的字段。 它由 HTML
<textarea>
表示。用户友好的表格
JSONField
在大多数情况下不是特别用户友好,但它是一种有用的方式来格式化来自客户端小部件的数据以提交到服务器。
范围字段
这组字段都共享用于接受范围数据的相似功能。 它们基于 MultiValueField。 他们将一个省略的值视为一个无界范围。 他们还验证下限不大于上限。 所有这些字段都使用 RangeWidget。
IntegerRangeField
- class IntegerRangeField
- 基于 IntegerField 并将其输入转换为
NumericRange
。 IntegerRangeField 和 BigIntegerRangeField 的默认值。
DecimalRangeField
- class DecimalRangeField
2.2 版中的新功能。
基于 DecimalField 并将其输入转换为
NumericRange
。 DecimalRangeField 的默认值。
FloatRangeField
- class FloatRangeField
基于 FloatField 并将其输入转换为
NumericRange
。 FloatRangeField 的默认值。自 2.2 版起已弃用: 改用 DecimalRangeField。
DateTimeRangeField
- class DateTimeRangeField
- 基于 DateTimeField 并将其输入转换为
DateTimeTZRange
。 DateTimeRangeField 的默认值。
小工具
RangeWidget
- class RangeWidget(base_widget, attrs=None)
所有范围字段使用的小部件。 基于 MultiWidget。
RangeWidget 有一个必需的参数:
- base_widget
RangeWidget 包含
base_widget
的 2 元组。
- decompress(value)
获取字段的单个“压缩”值,例如 DateRangeField,并返回表示下限和上限的元组。