Model¶
-
class
dbbase.model.
Model
(**kwargs)¶ Bases:
dbbase.model.Model
This class replicates some of the design features available when using flask_sqlalchemy. The primary interest is the embedding of references to the database via session and the query object.
selected elements are
db.session
db.Model
cls.query
To replicate the process, it needs to pull in db as an import to each model module.
Serialization:
There are class variables that can be set for models to control what shows for serialization. For more information look at the User Guide, but the following are the class variables used for this purpose.
When the following are set at default, serialize() will return the database columns plus any methods that have been created. To automatically exclude a method, name it with a starting _.
SERIAL_STOPLIST = None
SERIAL_FIELDS = None
SERIAL_FIELD_RELATIONS = None
If SERIAL_STOPLIST is a list of column names, those names will be excluded from serialization.
If SERIAL_FIELDS is a list, serialization will return ONLY those names in the list and in that order.
If SERIAL_FIELD_RELATIONS is a dict of related fields and a list of fields that would be used as SERIAL_FIELDS when serializing this class.
Methods
delete
()This function deletes and commits the object via session.
deserialize
(data[, from_camel_case, …])Convert back to column names that are more pythonic.
filter_columns
(column_props[, only_props, …])This function accepts a model class, a list of column properties to of interest.
This function returns a list of table properties that will be used in serialization.
save
()This function saves adds and commits the object via session.
serialize
([to_camel_case, level_limits, …])Output JSON formatted model.
to_dict
([to_camel_case, level_limits, sort, …])Returns columns in a dict.
validate_record
([camel_case])This function attempts to report any missing data from a record.
Attributes
SERIAL_FIELDS
SERIAL_FIELD_RELATIONS
SERIAL_STOPLIST
db
metadata
query