Phil
Phil

Reputation: 14651

How to subclass the default `db.Model` to use as a custom `Base` with SQLAlchemy

I have a flask application spread across modules with blueprints. Each module/blueprint has its own models.py file where models are defined.

With my desktop applications, using SQLAlchemy API directly, I would subclass object to define a Base class with some columns (ex: id, date_created ..), which then would serve as my declarative base (ex: Base = declarative_base(cls=Base)).

Upvotes: 3

Views: 2348

Answers (1)

DazWorrall
DazWorrall

Reputation: 14210

Simply set __abstract__ to True:

class BaseModel(db.Model):
    __abstract__ = True

Upvotes: 10

Related Questions