pyfarm.models.core.mixins module¶
Mixin Classes¶
Module containing mixins which can be used by multiple models.
-
class
pyfarm.models.core.mixins.
ModelTypes
(primary_keys, autoincrementing, columns, required, relationships, mappings)¶ Bases:
tuple
-
autoincrementing
¶ Alias for field number 1
-
columns
¶ Alias for field number 2
-
mappings
¶ Alias for field number 5
-
primary_keys
¶ Alias for field number 0
-
relationships
¶ Alias for field number 4
-
required
¶ Alias for field number 3
-
-
class
pyfarm.models.core.mixins.
ReprMixin
[source]¶ Bases:
object
Mixin which allows model classes to to convert columns into a more easily read object format.
Variables: - REPR_COLUMNS (tuple) – the columns to convert
- REPR_CONVERT_COLUMN (dict) – optional dictionary containing columns names and functions for converting to a more readable string format
-
REPR_COLUMNS
= NotImplemented¶
-
REPR_CONVERT_COLUMN
= {}¶
-
class
pyfarm.models.core.mixins.
UtilityMixins
[source]¶ Bases:
object
Mixins which can be used to produce dictionaries of existing data.
Const dict DICT_CONVERT_COLUMN: A dictionary containing key value pairs of attribute names and a function to retrieve the attribute. The function should take a single input and return the value itself. Optionally, you can also use the NotImplemented
object to exclude some columns from the results.-
DICT_CONVERT_COLUMN
= {}¶
-
to_dict
(unpack_relationships=True)[source]¶ Produce a dictionary of existing data in the table
Parameters: unpack_relationships (list, tuple, set, bool) – If True
then unpack all relationships. Ifunpack_relationships
is an iterable such as a list or tuple object then only unpack those relationships.
-
classmethod
to_schema
()[source]¶ Produce a dictionary which represents the table’s schema in a basic format
-
classmethod
types
()[source]¶ A classmethod that constructs a
namedtuple
object with four attributes:- primary_keys - set of all primary key(s) names
- autoincrementing - set of all columns which have autoincrement set
- columns - set of all column names
- required - set of all required columns (non-nullable wo/defaults)
- relationships - not columns themselves but do store relationships
- mappings - contains a dictionary with each field mapping to a Python type
-
-
class
pyfarm.models.core.mixins.
ValidatePriorityMixin
[source]¶ Bases:
object
Mixin that adds a state column and uses a class level STATE_ENUM attribute to assist in validation.
-
MAX_PRIORITY
= 1000¶
-
MIN_PRIORITY
= -1000¶
-