18 lines
657 B
Python
18 lines
657 B
Python
from sqlalchemy.ext.declarative import declared_attr
|
|
from sqlalchemy import Column, Integer, DateTime
|
|
from sqlalchemy.sql import func
|
|
|
|
|
|
class Base:
|
|
"""Base class for all database models."""
|
|
|
|
# Generate __tablename__ automatically
|
|
@declared_attr
|
|
def __tablename__(cls) -> str:
|
|
return cls.__name__.lower()
|
|
|
|
# Common columns for all models
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now(), nullable=False)
|
|
updated_at = Column(DateTime(timezone=True), server_default=func.now(),
|
|
onupdate=func.now(), nullable=False) |