PostgreSQL specific form fields and widgetsLink to this heading
All of these fields and widgets are available from the
django.contrib.postgres.forms module.
フィールドLink to this heading
SimpleArrayFieldLink to this heading
- class SimpleArrayField(base_field, delimiter=',', max_length=None, min_length=None)Link to this definition
A simple field which maps to an array. It is represented by an HTML
<input>.- base_fieldLink to this definition
This is a required argument.
It specifies the underlying form field for the array. This is not used to render any HTML, but it is used to process the submitted data and validate it. For example:
>>> 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
- delimiterLink to this definition
This is an optional argument which defaults to a comma:
,. This value is used to split the submitted data. It allows you to chainSimpleArrayFieldfor multidimensional data:>>> 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_lengthLink to this definition
This is an optional argument which validates that the array does not exceed the stated length.
- min_lengthLink to this definition
This is an optional argument which validates that the array reaches at least the stated length.
SplitArrayFieldLink to this heading
- class SplitArrayField(base_field, size, remove_trailing_nulls=False)Link to this definition
This field handles arrays by reproducing the underlying field a fixed number of times.
- base_fieldLink to this definition
This is a required argument. It specifies the form field to be repeated.
- sizeLink to this definition
This is the fixed number of times the underlying field will be used.
- remove_trailing_nullsLink to this definition
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_nullsisTrue, then null values are only allowed at the end, and will be stripped.Some examples:
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]
HStoreFieldLink to this heading
- class HStoreFieldLink to this definition
A field which accepts JSON encoded data for an
HStoreField. It casts all values (except nulls) to strings. It is represented by an HTML<textarea>.
JSONFieldLink to this heading
- class JSONFieldLink to this definition
A field which accepts JSON encoded data for a
JSONField. It is represented by an HTML<textarea>.
Range FieldsLink to this heading
This group of fields all share similar functionality for accepting range data.
They are based on MultiValueField. They treat one
omitted value as an unbounded range. They also validate that the lower bound is
not greater than the upper bound. All of these fields use
RangeWidget.
IntegerRangeFieldLink to this heading
- class IntegerRangeFieldLink to this definition
Based on
IntegerFieldand translates its input intoNumericRange. Default forIntegerRangeFieldandBigIntegerRangeField.
FloatRangeFieldLink to this heading
- class FloatRangeFieldLink to this definition
Based on
FloatFieldand translates its input intoNumericRange. Default forFloatRangeField.
DateTimeRangeFieldLink to this heading
- class DateTimeRangeFieldLink to this definition
Based on
DateTimeFieldand translates its input intoDateTimeTZRange. Default forDateTimeRangeField.
DateRangeFieldLink to this heading
- class DateRangeFieldLink to this definition
Based on
DateFieldand translates its input intoDateRange. Default forDateRangeField.
ウィジェットLink to this heading
RangeWidgetLink to this heading
- class RangeWidget(base_widget, attrs=None)Link to this definition
Widget used by all of the range fields. Based on
MultiWidget.RangeWidgethas one required argument:- base_widgetLink to this definition
A
RangeWidgetcomprises a 2-tuple ofbase_widget.
- decompress(value)Link to this definition
Takes a single "compressed" value of a field, for example a
DateRangeField, and returns a tuple representing and lower and upper bound.