
- Create base model with timestamp mixin - Add user model with roles - Add restaurant model - Add menu item model with categories - Add order and order item models - Add delivery model - Fix import issues and linting errors
25 lines
696 B
Python
25 lines
696 B
Python
from datetime import datetime
|
|
|
|
from sqlalchemy import Column, DateTime, Integer
|
|
from sqlalchemy.ext.declarative import declared_attr
|
|
|
|
from app.db.session import Base
|
|
|
|
|
|
class TimestampMixin:
|
|
"""Mixin that adds created_at and updated_at columns to models."""
|
|
|
|
created_at = Column(DateTime, default=datetime.utcnow, nullable=False)
|
|
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False)
|
|
|
|
|
|
class BaseModel(Base):
|
|
"""Base model for all models to inherit from."""
|
|
|
|
__abstract__ = True
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
|
|
@declared_attr
|
|
def __tablename__(cls):
|
|
return cls.__name__.lower() |