From 5ee9005ebb749e3f513f515d4774a1f76fa47c15 Mon Sep 17 00:00:00 2001 From: grillazz Date: Mon, 4 Apr 2022 20:22:21 +0200 Subject: [PATCH] add read only declarative base for shakespeare models --- the_app/models/base.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/the_app/models/base.py b/the_app/models/base.py index b386b91..547f841 100644 --- a/the_app/models/base.py +++ b/the_app/models/base.py @@ -6,6 +6,17 @@ from sqlalchemy.ext.asyncio import AsyncSession from sqlalchemy.ext.declarative import as_declarative, declared_attr +@as_declarative() +class BaseReadOnly: + id: Any + __name__: str + # Generate __tablename__ automatically + + @declared_attr + def __tablename__(cls) -> str: + return cls.__name__.lower() + + @as_declarative() class Base: id: Any