-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_setup.py
More file actions
110 lines (92 loc) · 3.41 KB
/
Copy pathdb_setup.py
File metadata and controls
110 lines (92 loc) · 3.41 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import os
import sys
from sqlalchemy import Column, ForeignKey, Integer, String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship, backref
from sqlalchemy import create_engine
Base = declarative_base()
class User(Base):
__tablename__ = 'user'
id = Column(Integer, primary_key=True)
user_name = Column(String(250), nullable=False, unique=True)
pass_word = Column(String(250), nullable=False)
@property
def serialize(self):
"""Return object data in easily serializeable format"""
return {
'user_name': self.user_name,
'pass_word': self.pass_word,
'id': self.id,
}
class Item(Base):
__tablename__ = 'vendor'
id = Column(Integer, primary_key=True)
product_id = Column(String(250), nullable=False)
product_name = Column(String(250), nullable=False)
weave = Column(String(250))
composition = Column(String(250))
color = Column(String(250))
category_1 = Column(String(250))
category_2 = Column(String(250))
category_3 = Column(String(250))
user_id = Column(Integer, ForeignKey('user.id'), nullable=False)
user = relationship(User)
@property
def serialize(self):
"""Return object data in easily serializeable format"""
return {
'id': self.id,
'product_id':self.product_id,
'product_name': self.product_name,
'weave':self.weave,
'composition':self.composition,
'color':self.color,
'category_1':self.category_1,
'category_2':self.category_2,
'category_3':self.category_3,
'user_id': self.user_id,
}
class Order(Base):
__tablename__ = 'order'
id = Column(Integer, primary_key=True)
order_id = Column(String(250), nullable=False)
product_code = Column(String(250), nullable=False)
order_type = Column(String(250))
delivery_distance = Column(String(250))
delivery_time = Column(String(250))
@property
def serialize(self):
"""Return object data in easily serializeable format"""
return {
'id': self.id,
'order_id':self.order_id,
'product_code': self.product_code,
'order_type':self.order_type,
'delivery_distance':self.delivery_distance,
'delivery_time':self.delivery_time
}
class Product(Base):
__tablename__ = 'product'
id = Column(Integer, primary_key=True)
product_id = Column(String(250), nullable=False)
product_code = Column(String(250), nullable=False)
composition = Column(String(250))
color = Column(String(250))
pattern = Column(String(250))
weave = Column(String(250))
image_link = Column(String(250))
@property
def serialize(self):
"""Return object data in easily serializeable format"""
return {
'id': self.id,
'product_id':self.product_id,
'product_code': self.product_code,
'composition':self.composition,
'color':self.color,
'pattern':self.pattern,
'weave':self.weave,
'image_link':self.image_link,
}
engine = create_engine('sqlite:///fm.db')
Base.metadata.create_all(engine)