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

flask, flask-sqlalchemy, python, sqlalchemy, sqlite

Solution

Simply set `__abstract__` to `True`:

class BaseModel(db.Model):
    __abstract__ = True

Problem

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)`). - How can I subclass `flask-SQLALchemy`'s `db.Model` so that I can use it as a Base with default columns which I want all tables to have?

Original source