MultiValueField
Aggregate the logic of multiple Fields.
Attributes
| Attribute | Type | Description |
|---|---|---|
| default_error_messages | dict = {'invalid': 'Enter a list of values.', 'incomplete': 'Enter a complete value.'} | A dictionary of error message templates used to provide feedback for invalid or incomplete input data. |
Constructor
Signature
def MultiValueField(
fields: list,
require_all_fields: boolean = True,
**kwargs: dict
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| fields | list | A list or tuple of Field instances that compose this MultiValueField. |
| require_all_fields | boolean = True | If True, validation fails if any individual field is empty. If False, individual field requirements are respected. |
| **kwargs | dict | Additional keyword arguments passed to the parent Field class constructor. |
Methods
validate()
@classmethod
def validate(
value: any
) - > null
Performs additional validation on the compressed value; this implementation is a placeholder for subclass overrides.
Parameters
| Name | Type | Description |
|---|---|---|
| value | any | The single compressed value produced after cleaning all individual sub-fields. |
Returns
| Type | Description |
|---|---|
null | Nothing is returned. |
clean()
@classmethod
def clean(
value: list
) - > any
Validate every value in the given list. A value is validated against the corresponding Field in self.fields.
Parameters
| Name | Type | Description |
|---|---|---|
| value | list | A list or tuple of values where each element corresponds to a specific sub-field in the MultiValueField. |
Returns
| Type | Description |
|---|---|
any | The single compressed value resulting from the combined and validated input list. |
compress()
@classmethod
def compress(
data_list: list
) - > any
Return a single value for the given list of values. The values can be assumed to be valid.
Parameters
| Name | Type | Description |
|---|---|---|
| data_list | list | A list of cleaned and validated values from the individual sub-fields. |
Returns
| Type | Description |
|---|---|
any | A single combined value, such as a datetime object created from separate date and time inputs. |
has_changed()
@classmethod
def has_changed(
initial: any,
data: list
) - > boolean
Determines if the current input data differs from the initial value by comparing each sub-field individually.
Parameters
| Name | Type | Description |
|---|---|---|
| initial | any | The original value of the field, which may be a single object or a list of values. |
| data | list | The current submitted data to be compared against the initial state. |
Returns
| Type | Description |
|---|---|
boolean | True if any sub-field value has changed compared to its initial state, False otherwise. |