35 lines
No EOL
1.2 KiB
Python
35 lines
No EOL
1.2 KiB
Python
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):
|
|
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):
|
|
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"]] = db.relationship("Item", backref="post") |