Spaces:
Sleeping
Sleeping
Download models.py from EliramShemesh/Spender: direct link, hf CLI and curl.
- Browser
- Download file 4.5 kB
-
https://huggingface.co/spaces/EliramShemesh/Spender/resolve/main/models.py
- Command line
-
hf download hf://spaces/EliramShemesh/Spender/models.py
-
curl -L -o models.py https://huggingface.co/spaces/EliramShemesh/Spender/resolve/main/models.py
4.5 kB
| from datetime import datetime | |
| from enum import Enum | |
| from typing import Optional, List | |
| from sqlmodel import SQLModel, Field, Relationship | |
| class TransactionType(str, Enum): | |
| EXPENSE = "EXPENSE" | |
| INCOME = "INCOME" | |
| class User(SQLModel, table=True): | |
| id: Optional[int] = Field(default=None, primary_key=True) | |
| name: str | |
| username: str = Field(unique=True, index=True) | |
| hashed_password: str | |
| icon: str = "๐ค" | |
| transactions: List["Transaction"] = Relationship(back_populates="user") | |
| class Category(SQLModel, table=True): | |
| id: Optional[int] = Field(default=None, primary_key=True) | |
| name: str | |
| type: TransactionType | |
| icon: str = "๐ฐ" | |
| color: str = "#007AFF" | |
| budget: Optional[float] = Field(default=None) | |
| sub_categories: List["SubCategory"] = Relationship(back_populates="category") | |
| transactions: List["Transaction"] = Relationship(back_populates="category") | |
| class SubCategory(SQLModel, table=True): | |
| id: Optional[int] = Field(default=None, primary_key=True) | |
| name: str | |
| icon: str = "๐" | |
| budget: Optional[float] = Field(default=None) | |
| category_id: int = Field(foreign_key="category.id", ondelete="CASCADE", index=True) | |
| category: Category = Relationship(back_populates="sub_categories") | |
| transactions: List["Transaction"] = Relationship(back_populates="sub_category") | |
| class PaymentMethod(SQLModel, table=True): | |
| id: Optional[int] = Field(default=None, primary_key=True) | |
| name: str | |
| icon: str = "๐ณ" | |
| transactions: List["Transaction"] = Relationship(back_populates="payment_method") | |
| class InstallmentPlan(SQLModel, table=True): | |
| id: Optional[int] = Field(default=None, primary_key=True) | |
| amount: float | |
| notes: str | |
| payee: Optional[str] = Field(default=None) | |
| start_date: datetime = Field(default_factory=datetime.utcnow, index=True) | |
| type: TransactionType | |
| total_installments: Optional[int] = None | |
| posted_installments: int = Field(default=1) | |
| recurring_forever: bool = Field(default=False) | |
| end_date: Optional[datetime] = Field(default=None, index=True) | |
| user_id: int = Field(foreign_key="user.id", index=True) | |
| category_id: int = Field(foreign_key="category.id", ondelete="CASCADE", index=True) | |
| sub_category_id: Optional[int] = Field(default=None, foreign_key="subcategory.id", ondelete="CASCADE", index=True) | |
| payment_method_id: Optional[int] = Field(default=None, foreign_key="paymentmethod.id", index=True) | |
| class BudgetHistory(SQLModel, table=True): | |
| id: Optional[int] = Field(default=None, primary_key=True) | |
| category_id: Optional[int] = Field(default=None, foreign_key="category.id", ondelete="CASCADE", index=True) | |
| sub_category_id: Optional[int] = Field(default=None, foreign_key="subcategory.id", ondelete="CASCADE", index=True) | |
| budget: float | |
| updated_at: datetime = Field(default_factory=datetime.utcnow, index=True) | |
| class PushSubscription(SQLModel, table=True): | |
| id: Optional[int] = Field(default=None, primary_key=True) | |
| endpoint: str = Field(index=True) | |
| p256dh: str | |
| auth: str | |
| user_id: int = Field(foreign_key="user.id", index=True) | |
| created_at: datetime = Field(default_factory=datetime.utcnow) | |
| class Transaction(SQLModel, table=True): | |
| id: Optional[int] = Field(default=None, primary_key=True) | |
| amount: float | |
| notes: str # Renamed from description | |
| payee: Optional[str] = Field(default=None) # ืืื ืฉืืื | |
| date: datetime = Field(default_factory=datetime.utcnow, index=True) | |
| type: TransactionType | |
| # Installments | |
| is_installment: bool = Field(default=False, index=True) | |
| installment_number: Optional[int] = None | |
| total_installments: Optional[int] = None | |
| installment_plan_id: Optional[int] = Field(default=None, foreign_key="installmentplan.id", index=True) | |
| user_id: int = Field(foreign_key="user.id", index=True) | |
| category_id: int = Field(foreign_key="category.id", ondelete="CASCADE", index=True) | |
| sub_category_id: Optional[int] = Field(default=None, foreign_key="subcategory.id", ondelete="CASCADE", index=True) | |
| payment_method_id: Optional[int] = Field(default=None, foreign_key="paymentmethod.id", index=True) | |
| user: User = Relationship(back_populates="transactions") | |
| category: Category = Relationship(back_populates="transactions") | |
| sub_category: Optional[SubCategory] = Relationship(back_populates="transactions") | |
| payment_method: Optional[PaymentMethod] = Relationship(back_populates="transactions") | |