-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
102 lines (78 loc) · 2.49 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
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
from sqlalchemy import Column, ForeignKey, Integer, String, Float
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import create_engine
import sys
import datetime
from passlib.apps import custom_app_context as pwd_context
Base = declarative_base()
class User(Base):
__tablename__ = 'user'
id = Column(Integer, primary_key=True)
name = Column(String(250), nullable=False)
email = Column(String(250), nullable=False)
password_hash = Column(String(64))
def hash_password(self, password):
self.password_hash = pwd_context.hash(password)
def verify_password(self, password):
return pwd_context.verify(password, self.password_hash)
@property
def serialize(self):
return {
'id' : self.id,
'name' : self.name,
'email' :self.email,
'picture' : self.picture,
}
class Categories(Base):
__tablename__ = 'categories'
id = Column(Integer, primary_key=True)
name = Column(String(250), nullable=False)
image = Column(String(250), nullable=False)
description = Column(String(250), nullable=False)
user_id = Column(Integer, ForeignKey('user.id'))
user = relationship(User)
@property
def serialize(self):
return {
'name': self.name,
'id' : self.id,
}
class Feedback(Base):
__tablename__ = 'feedback'
name = Column(String(100), nullable=False)
id = Column(Integer, primary_key=True)
rating1 = Column(Integer, default=0)
rating2 = Column(Integer, default=0)
rating3 = Column(Integer, default=0)
rating4 = Column(Integer, default=0)
rating5 = Column(Integer, default=0)
totalrating = Column(Integer, default=0)
avgratings = Column(Float, default=0)
categories_id = Column(Integer, ForeignKey('categories.id'))
categories = relationship(Categories)
user_id = Column(Integer, ForeignKey('user.id'))
user = relationship(User)
@property
def serialize(self):
return {
'name' : self.name,
'description' : self.description,
'id' : self.id,
'rating' : self.rating,
}
class Comments(Base):
__tablename__ = 'comments'
id = Column(Integer, primary_key=True)
commentdata = Column(String(250), nullable=False)
time = Column(String)
rate = Column(Integer, default=0)
categories_id = Column(Integer, ForeignKey('categories.id'))
categories = relationship(Categories)
user_id = Column(Integer, ForeignKey('user.id'))
user = relationship(User)
feedback_id = Column(Integer, ForeignKey('feedback.id'))
feedback = relationship(Feedback)
engine = create_engine(
'sqlite:///problems.db')
Base.metadata.create_all(engine)