Base Model¶
We extends the peewee.Model class to integrate with the
server-side processing logic of DataTables. Some monkeypathes
were made as certain functionalities with peewee are not
correctly implemented.
- class flask_datatables.model.Model(*args, **kwargs)[source]¶
 Bases:
ModelExtends
peewee.Modelwith DataTables support.To ease the
Modelclass from recursively processing its field data, we added the following two attributes to save the DataTables integrated fields data.- dt_orderable: Dict[str, Field] = {}¶
 DataTables orderable fields.
- dt_searchable: Dict[str, Field] = {}¶
 DataTables searchable fields.
- classmethod validate_model()[source]¶
 Validates data model and dynamically insert fields.
If DataTables integration is enabled for the data model, this method will insert fields (database columns) for both order and search operations respectively on each defined fields according to the original field type definition.
By default, each field is orderable and/or searchable as long as the
datatablesswitch is enabled. When theorderableand/orsearchableattributes are set to an instance of aField,Flask-DataTableswill insert additional fields of such type with_dt_orderand/or_dt_searchsuffix as the field names accordingly.- Return type:
 
- save(force_insert=False, only=None)[source]¶
 Save the data in the model instance.
The method extends the original
peewee.Model.save()method by automatically update the searching and ordering field data with the actual data.
- classmethod search(query=None, factory=None)[source]¶
 Server-side processing integration with DataTables.
- Parameters:
 - Return type:
 - Returns:
 Selected information from the database in format to be sent to DataTables.
See also
The
factoryfunction takes exactly one parameter, the data record returned frompeeweeselection, and returns the converted data of fields. Seeflask_datatables.utils.prepare_response()for an example.
- class flask_datatables.model.Metadata(model, database=None, table_name=None, indexes=None, primary_key=None, constraints=None, schema=None, only_save_dirty=False, depends_on=None, options=None, db_table=None, table_function=None, table_settings=None, without_rowid=False, temporary=False, strict_tables=None, legacy_table_names=True, **kwargs)[source]¶
 Bases:
MetadataBasic metadata for data models.
Flask-DataTablesextends the original metadata record frompeeweewith adatatablesswitch to indicate if current data model supports and/or enables DataTables server-side processing integration.- 
datatables: 
bool= False¶ DataTables integration indicator flag.
- 
datatables: