Files
finance_app/backend/app/models/budget.py

26 lines
1.4 KiB
Python

from datetime import datetime, date
from decimal import Decimal
from sqlalchemy import String, Boolean, Numeric, ForeignKey, Date, DateTime, func
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.database import Base
class Budget(Base):
__tablename__ = "budgets"
id: Mapped[int] = mapped_column(primary_key=True)
user_id: Mapped[int] = mapped_column(ForeignKey("users.id"), nullable=False, index=True)
category_id: Mapped[int] = mapped_column(ForeignKey("categories.id"), nullable=False)
name: Mapped[str] = mapped_column(String(200), nullable=False)
amount: Mapped[Decimal] = mapped_column(Numeric(20, 2), nullable=False)
currency_id: Mapped[int] = mapped_column(ForeignKey("currencies.id"), nullable=False)
period_type: Mapped[str] = mapped_column(String(20), nullable=False) # monthly | weekly | yearly | custom
start_date: Mapped[date] = mapped_column(Date, nullable=False)
end_date: Mapped[date | None] = mapped_column(Date)
is_active: Mapped[bool] = mapped_column(Boolean, default=True, nullable=False)
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
user: Mapped["User"] = relationship("User", back_populates="budgets")
category: Mapped["Category"] = relationship("Category", back_populates="budgets")
currency: Mapped["Currency"] = relationship("Currency", back_populates="budgets")