This repository has been archived by the owner on Aug 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodels.py
97 lines (78 loc) · 3.06 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
import os
import sys
from sqlalchemy import (Column, DateTime, ForeignKey, Integer, String,
Boolean, create_engine, func)
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship
Base = declarative_base()
class Users(Base):
__tablename__ = 'users'
user_id = Column(Integer, primary_key=True)
provider = Column(String(8), nullable=False)
name = Column(String(250), nullable=False)
email = Column(String(250), nullable=False)
picture = Column(String(250))
is_admin = Column(Boolean, nullable=False)
class Collection(Base):
__tablename__ = 'collection'
coll_id = Column(Integer, primary_key=True)
name = Column(String(50), nullable=False)
description = Column(String(130))
submit_date = Column(DateTime, default=func.now())
path = Column(String(50), nullable=False, unique=True)
user_id = Column(Integer, ForeignKey('users.user_id'))
users = relationship(Users)
category = relationship("Category", cascade="all, delete-orphan")
link = relationship("Link", cascade="all, delete-orphan")
@property
def serialize(self):
"""Return object data in easily serializeable format"""
return {
'name': self.name,
'description': self.description,
'path': self.path
}
class Category(Base):
__tablename__ = 'category'
cat_id = Column(Integer, primary_key=True)
name = Column(String(100), nullable=False)
description = Column(String(200))
submit_date = Column(DateTime, default=func.now())
path = Column(String(50), nullable=False)
coll_id = Column(Integer, ForeignKey('collection.coll_id'))
collection = relationship(Collection)
user_id = Column(Integer, ForeignKey('users.user_id'))
users = relationship(Users)
link = relationship("Link", cascade="all, delete-orphan")
@property
def serialize(self):
"""Return object data in easily serializeable format"""
return {
'name': self.name,
'description': self.description,
'path': self.path
}
class Link(Base):
__tablename__ = 'link'
link_id = Column(Integer, primary_key=True)
name = Column(String(100), nullable=False)
url = Column(String(200), nullable=False)
description = Column(String(300))
submit_date = Column(DateTime, default=func.now())
cat_id = Column(Integer, ForeignKey('category.cat_id'))
category = relationship(Category)
coll_id = Column(Integer, ForeignKey('collection.coll_id'))
collection = relationship(Collection)
user_id = Column(Integer, ForeignKey('users.user_id'))
users = relationship(Users)
@property
def serialize(self):
"""Return object data in easily serializeable format"""
return {
'id': self.link_id,
'name': self.name,
'url': self.url,
'description': self.description,
}
engine = create_engine('postgresql:///links')
Base.metadata.create_all(engine)