Base
File that contains Base Models that is to be inherited by all models.
The four bases currently available:
BaseAttachmentDataTable
Bases: BaseDataTable
Model to hold attachment data that has a many-to-many relationship with the primary data.
Source code in samudra/models/base.py
__attach__(other, values)
classmethod
A custom dunder method to attach a single row of attachment data to the primary data.
Is expected to be used when a other.attach(cls, *args, *kwargs)
method is called.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
BaseDataTable
|
An instance of the primary data. |
required |
values |
List[Dict[field, value]]
|
A field:value pair related to this class. |
required |
Raises:
Type | Description |
---|---|
AttributeError
|
Raised when the connection table is not set. |
Returns:
Type | Description |
---|---|
pw.ModelSelect
|
pw.ModelSelect: A list of rows of this table associated with |
Source code in samudra/models/base.py
connects_to(other, through)
classmethod
Create a dict that defines connection with data and its relationship table
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
BaseDataTable
|
The data to attach the connection |
required |
through |
BaseRelationshipTable
|
The bridge that holds the many-to-many connections |
required |
Source code in samudra/models/base.py
with_dependencies()
classmethod
List itself and dependencies tables.
BaseDataTable
Bases: pw.Model
The simplest type of data model. All other models derive from this model including other base models.
Fields
id
(AutoField): the unique id of the data- primary_key: True
tarikh_masuk
(TimestampField): the time it enters the database
Meta
Meta is subclass of BaseDataTable
to hold metadata
Attr(Meta)
legacy_table_names
(bool): The naming scheme of models in SQL Tables. Set toFalse
, so thatCamelCase
model classnames are converted intocamel_case
table names in the database. (If set toTrue
,CamelCase
âž¡camelcase
)
Source code in samudra/models/base.py
BaseRelationshipTable
Bases: BaseDataTable
Model to hold many-to-many relationships.
Model classes are named ModelAXModelB
where
ModelA
is any BaseAttachmentDataTable
and
ModelB
is any BaseDataTable
.
Source code in samudra/models/base.py
BaseStrictDataTable
Bases: BaseDataTable
Model to hold finitely defined data.
Source code in samudra/models/base.py
get_or_create(*args, **kwargs)
classmethod
Overrides the default cls.get_or_create()
method to render it unusable.
A finitely defined data must be explicitly defined.
Raises:
Type | Description |
---|---|
AttributeError
|
This method should not be used by the inheriting model. |