HStoreField
A field for HStore data which accepts dictionary JSON input.
Attributes
| Attribute | Type | Description |
|---|---|---|
| widget | class = forms.Textarea | The form widget class used to render the HStore input field, defaulting to a multi-line text area. |
| default_error_messages | dict | A dictionary containing localized error messages for handling invalid JSON data or incorrect input formats. |
Methods
prepare_value()
@classmethod
def prepare_value(
value: dict|any
) - > string
Converts the dictionary value into a JSON-formatted string for display in the form widget.
Parameters
| Name | Type | Description |
|---|---|---|
| value | `dict | any` |
Returns
| Type | Description |
|---|---|
string | A JSON string representation of the dictionary, or the original value if it is not a dictionary. |
to_python()
@classmethod
def to_python(
value: string|dict
) - > dict
Parses the raw JSON input string into a dictionary and ensures all values are cast to strings. Raises a ValidationError if the input is not valid JSON or not a dictionary.
Parameters
| Name | Type | Description |
|---|---|---|
| value | `string | dict` |
Returns
| Type | Description |
|---|---|
dict | A dictionary where all non-null values have been converted to strings. |
has_changed()
@classmethod
def has_changed(
initial: any,
data: any
) - > boolean
Return True if data differs from initial.
Parameters
| Name | Type | Description |
|---|---|---|
| initial | any | The original value of the field used for comparison. |
| data | any | The new data submitted via the form to check for changes. |
Returns
| Type | Description |
|---|---|
boolean | True if the submitted data represents a change from the initial value, False otherwise. |