Added buy capability to view with dialog Added additional properties to Item (url and imageurl); NEEDS TESTING Made delete items work properly
42 lines
1.4 KiB
Python
42 lines
1.4 KiB
Python
from app import db
|
|
from sqlalchemy.orm import Mapped, mapped_column, RelationshipProperty, relationship
|
|
from sqlalchemy import Uuid, String, Text, String, ForeignKey
|
|
from uuid import uuid4 as uuid, UUID
|
|
|
|
|
|
class Item(db.Model):
|
|
def __init__(
|
|
self, title: str, description: str, price: float, url: str, image: str
|
|
):
|
|
self.bought = False
|
|
self.wishlist_id = None
|
|
self.title = title
|
|
self.description = description
|
|
self.price = price
|
|
self.url = url
|
|
self.image = image
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
wishlist_id: Mapped[int | None] = mapped_column(ForeignKey("wishlist.id"))
|
|
title: Mapped[str] = mapped_column(String(250))
|
|
description: Mapped[str] = mapped_column(Text)
|
|
price: Mapped[float] = mapped_column()
|
|
url: Mapped[str] = mapped_column(Text)
|
|
image: Mapped[str] = mapped_column(Text)
|
|
bought: Mapped[bool] = mapped_column()
|
|
|
|
|
|
class Wishlist(db.Model):
|
|
def __init__(self, title: str, description: str):
|
|
self.editId = uuid()
|
|
self.viewId = uuid()
|
|
self.title = title
|
|
self.description = description
|
|
|
|
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"]] = relationship("Item", backref="post")
|