Skip to main content

MultiValueField

Aggregate the logic of multiple Fields.

Attributes

AttributeTypeDescription
default_error_messagesdict = {'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

NameTypeDescription
fieldslistA list or tuple of Field instances that compose this MultiValueField.
require_all_fieldsboolean = TrueIf True, validation fails if any individual field is empty. If False, individual field requirements are respected.
**kwargsdictAdditional 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

NameTypeDescription
valueanyThe single compressed value produced after cleaning all individual sub-fields.

Returns

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

NameTypeDescription
valuelistA list or tuple of values where each element corresponds to a specific sub-field in the MultiValueField.

Returns

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

NameTypeDescription
data_listlistA list of cleaned and validated values from the individual sub-fields.

Returns

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

NameTypeDescription
initialanyThe original value of the field, which may be a single object or a list of values.
datalistThe current submitted data to be compared against the initial state.

Returns

TypeDescription
booleanTrue if any sub-field value has changed compared to its initial state, False otherwise.