Implemented basic models
This commit is contained in:
parent
6bceef1664
commit
3ba6099976
16 changed files with 257 additions and 24 deletions
|
|
@ -1,20 +1,35 @@
|
|||
from typing import List
|
||||
from app import db
|
||||
|
||||
from sqlalchemy.orm import Mapped, mapped_column, RelationshipProperty
|
||||
from sqlalchemy import Uuid, String, Text
|
||||
from uuid import uuid4 as uuid
|
||||
|
||||
class Item(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
title = db.Column(db.String(250))
|
||||
description = db.Column(db.Text)
|
||||
price = db.Column(db.Float)
|
||||
bought = db.Column(db.Boolean)
|
||||
def __init__(self, title: str, description: str, price: float):
|
||||
self.wishlist_id = None
|
||||
self.title = title
|
||||
self.description = description
|
||||
self.price = price
|
||||
self.bought = False
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
wishlist_id: Mapped[int | None] = mapped_column(db.ForeignKey("wishlist.id"))
|
||||
title: Mapped[str] = mapped_column(db.String(250))
|
||||
description: Mapped[str] = mapped_column(db.Text)
|
||||
price: Mapped[float] = mapped_column()
|
||||
bought: Mapped[bool] = mapped_column()
|
||||
|
||||
class Wishlist(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
editId = db.Column(db.Uuid)
|
||||
viewId = db.Column(db.Uuid)
|
||||
title = db.Column(db.String(250))
|
||||
description = db.Column(db.Text)
|
||||
def __init__(self, title: str, description: str):
|
||||
self.editId = uuid()
|
||||
self.viewId = uuid()
|
||||
self.title = title
|
||||
self.description = description
|
||||
|
||||
itemIds = db.Column(db.ARRAY(db.Integer)) # Store item IDs as an array
|
||||
items = db.relationship("Item", primaryjoin="Wishlist.itemIds")
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
editId: Mapped[Uuid] = mapped_column(Uuid)
|
||||
viewId: Mapped[Uuid] = mapped_column(Uuid)
|
||||
title: Mapped[str] = mapped_column(String(250))
|
||||
description: Mapped[str] = mapped_column(Text)
|
||||
|
||||
items: Mapped[List["Item"]] = db.relationship("Item", backref="post")
|
||||
Loading…
Add table
Add a link
Reference in a new issue