Skip to content

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 β€” If True, the model is abstract: it has no table, no objects manager, and cannot be instantiated. Used for model inheritance; subclasses inherit fields and can inherit this config. Default is False.

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.