forked from CameronGuthrie/LBG-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
45 lines (37 loc) · 1.08 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
STRING = 40
TEXT = 240
class ItemModel(db.Model):
"""
ItemModel class for ORM
"""
__tablename__ = "items"
_id = db.Column(db.Integer, primary_key=True)
description = db.Column(db.String(TEXT))
name = db.Column(db.String(STRING))
price = db.Column(db.Float())
def __init__(self, _id: int, description: str, name: str, price: float):
"""
class constructor
"""
self.description = description
self.name = name
self.price = price
self._id = _id
def __str__(self) -> str:
"""
string representation method for object
"""
return f"'description':{self.description},'name':{self.name},'price':{self.price},'_id':{self._id}"
@property
def serialize(self) -> dict[str, str | int | float]:
"""
serializable format for object
"""
return {
'description': self.description,
'name': self.name,
'price': self.price,
'_id': self._id
}