24 lines
612 B
Python
24 lines
612 B
Python
import datetime
|
|
from typing import Any
|
|
|
|
from sqlalchemy import Column, DateTime
|
|
from sqlalchemy.ext.declarative import as_declarative, declared_attr
|
|
|
|
|
|
@as_declarative()
|
|
class Base:
|
|
"""Base class for all models."""
|
|
id: Any
|
|
__name__: str
|
|
|
|
# Generate __tablename__ automatically based on class name
|
|
@declared_attr
|
|
def __tablename__(cls) -> str:
|
|
return cls.__name__.lower()
|
|
|
|
created_at = Column(DateTime, default=datetime.datetime.utcnow)
|
|
updated_at = Column(
|
|
DateTime,
|
|
default=datetime.datetime.utcnow,
|
|
onupdate=datetime.datetime.utcnow
|
|
) |