Model config
Model Config¶
The behavior of Pydbm can be controlled via the Config class on a model.
from pydbm import DbmModel
__all__ = (
"UserModel",
)
class UserModel(DbmModel):
username: str
password: str
class Config:
unique_together = ("username",)
table_name = "users"
In Pydbm, the default behavior of the model is to use the model’s name as the table_name, and the unique_together is set to all the fields.
Config options¶
table_nameβ Name of the database table (default: model name lowercased +s, e.g.UserModelβusermodels).unique_togetherβ Tuple of field names used to generate and look up the primary key (default: all fields).abstractβ IfTrue, the model is abstract: it has no table, noobjectsmanager, and cannot be instantiated. Used for model inheritance; subclasses inherit fields and can inherit this config. Default isFalse.
Config inheritance¶
When a model subclasses another and does not define its own Config, it inherits unique_together from the first base that has a Config. The table name is always generated from the subclass name, not inherited. See Model inheritance in the models tutorial.