Skip to content

Commit

Permalink
Added relationship between receipt and item
Browse files Browse the repository at this point in the history
  • Loading branch information
Mythridor committed Aug 19, 2024
1 parent 40e4ade commit 7b84096
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 26 deletions.
File renamed without changes.
28 changes: 28 additions & 0 deletions spendizer/model/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import datetime
import uuid
from sqlmodel import Field, SQLModel, Relationship


class Receipt(SQLModel, table=True):
id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True)
date: datetime.datetime = Field(nullable=False)
market_id: uuid.UUID = Field(foreign_key='marketplace.id', nullable=False)
total: float = Field(nullable=False)
items: list['Item'] = Relationship(
back_populates='receipt', nullable=False
)


class Item(SQLModel, table=True):
id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True)
name: str = Field(nullable=False)
receipt_id: uuid.UUID | None = Field(
default=None, foreign_key='receipt.id'
)
unit_price: float = Field(nullable=False)
receipt: Receipt = Relationship(back_populates='items', nullable=False)


class Marketplace(SQLModel, table=True):
id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True)
name: str = Field(nullable=False)
26 changes: 0 additions & 26 deletions spendizer/sql/model/main.py

This file was deleted.

0 comments on commit 7b84096

Please sign in to comment.