Inner model types

Internal types for dirty models

class dirty_models.model_types.ListModel(seq=None, *args, **kwargs)[source]

Bases: dirty_models.base.InnerFieldTypeMixin, dirty_models.base.BaseData

Dirty model for a list. It has the behavior to work as a list implementing its methods and has also the methods export_data, export_modified_data, import_data and flat_data to work also as a model, storing original and modified values.

append(item)[source]

Appending elements to our list

clear()[source]

Resets our list, keeping original data

clear_all()[source]

Resets our list

clear_modified_data()[source]

Clears only the modified data

count(value)[source]

Gives the number of occurrencies of a value in the list

delete_attr_by_path(field)[source]

Function for deleting a field specifying the path in the whole model as described in dirty:models.models.BaseModel.perform_function_by_path()

export_data()[source]

Retrieves the data in a jsoned form

export_deleted_fields()[source]

Returns a list with any deleted fields form original data. In tree models, deleted fields on children will be appended.

export_modifications()[source]

Returns list modifications.

export_modified_data()[source]

Retrieves the modified data in a jsoned form

export_original_data()[source]

Retrieves the original_data

extend(iterable)[source]

Given an iterable, it adds the elements to our list

flat_data()[source]

Function to pass our modified values to the original ones

get_1st_attr_by_path(field_path, **kwargs)[source]

It returns first value looked up by field path. Field path is dot-formatted string path: parent_field.child_field.

Parameters:
  • field_path (str) – field path. It allows * as wildcard.
  • default – Default value if field does not exist. If it is not defined AttributeError exception will be raised.
Returns:

value

get_attrs_by_path(field_path, stop_first=False)[source]

It returns list of values looked up by field path. Field path is dot-formatted string path: parent_field.child_field.

Parameters:
  • field_path (list or None.) – field path. It allows * as wildcard.
  • stop_first (bool) – Stop iteration on first value looked up. Default: False.
Returns:

value

get_validated_object(value)[source]

Returns the value validated by the field_type

import_data(data)[source]

Uses data to add it to the list

import_deleted_fields(data)[source]

Set data fields to deleted

index(value)[source]

Gets the index in the list for a value

initialise_modified_data()[source]

Initialise the modified_data if necessary

insert(index, p_object)[source]

Insert an element to a list

is_modified()[source]

Returns whether list is modified or not

pop(*args)[source]

Obtains and delete the element from the list

remove(value)[source]

Deleting an element from the list

reset_attr_by_path(field)[source]

Function for restoring a field specifying the path in the whole model as described in dirty:models.models.BaseModel.perform_function_by_path()

reverse()[source]

Reverses the list order

sort()[source]

Sorts the list

dirty_models.model_types.modified_data_decorator(function)[source]

Decorator to initialise the modified_data if necessary. To be used in list functions to modify the list