More about Models & Model.Meta

Model.Meta

class wefram.ds.orm.model.Meta(cls: wefram.ds.orm.model._ModelMetaclass, app_name: str, module_name: str)

The model’s subclass describing some optionals and service methods for the ORM class.

model: ClassVar

the class of the corresponding ORM model

module_name: str

the name of the module where this model is declared at

app_name: str

the name of the app where this model is declared at

caption: str

statically set caption of the model

caption_plural: str

statically set caption of the model instance when speaking about several instances (two or more)

caption_key: Optional[str]

the attribute name which about to be user as caption of the model instance, if applicable

class MyModel(ds.Model):
    id = ds.UUIDPrimaryKey()
    name = ds.Column(ds.String(100), nullable=False, default='')
    value = ds.Column(ds.String(255))

    class Meta:
        caption_key = 'name'
hidden: Optional[List[str]]

the array of model attributes names whose will not be included in the resulting dict, generated by dict() or json() methods of the Model class

class MyModel(ds.Model):
    ...

    class Meta:
        hidden = ['password', 'secret']
include: Optional[List[str]]

the array of model attributes names whose normally not about to be included in the resulting dict, generated by dict() or json() of the Model class, but has to be

class MyModel(ds.Model):
    ...

    class Meta:
        include = ['some_property', 'some_non_column'] 
attributes: list

the array of model attributes

columns: list

the array of model columns

attributes_sets: Optional[Dict[str, Sequence[str]]]

a dict of sets of attributes, useful when need to return only specific attributes of the model in the resuling dict, generated by dict() or json() methods of the Model, formed as set name and corresponding list of the set attributes

class MyModel(ds.Model):
    id = ds.UUIDPrimaryKey()
    name = ds.Column(ds.String(100), nullable=False, default='')
    public = ds.Column(ds.String(255))
    other = ds.Column(ds.String(255))

    class Meta:
        attributes_sets = {
            'publics': ['id', 'name', 'public'],
            'identity': ['id', 'name']
        }
repr_by: Optional[List[str]]

the list of attribute names used to (repr) the model instance, which may help programmer to identify the object as the specific instance; for example, default repr with set repr_by to [‘id’, ‘name’] will result in something like: <MyModel id=1 name=My name>

findable: Optional[List[str]]

the list of attribute names used to find by a textual term

order: Optional[Union[str, List[str], sqlalchemy.sql.schema.Column, List[sqlalchemy.sql.schema.Column]]]

the default sorting rule, in the format used by SQLAclhemy with default ‘sort’

history: wefram.ds.orm.model.History

(history)