Skip to main content

HStoreField

A field for HStore data which accepts dictionary JSON input.

Attributes

AttributeTypeDescription
widgetclass = forms.TextareaThe form widget class used to render the HStore input field, defaulting to a multi-line text area.
default_error_messagesdictA 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

NameTypeDescription
value`dictany`

Returns

TypeDescription
stringA 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

NameTypeDescription
value`stringdict`

Returns

TypeDescription
dictA 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

NameTypeDescription
initialanyThe original value of the field used for comparison.
dataanyThe new data submitted via the form to check for changes.

Returns

TypeDescription
booleanTrue if the submitted data represents a change from the initial value, False otherwise.