-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
93 lines (68 loc) · 2.71 KB
/
Copy pathmodels.py
File metadata and controls
93 lines (68 loc) · 2.71 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
from jobapp import db
import datetime
def init_db():
db.drop_all()
db.create_all()
class PostCount(db.Model):
id = db.Column(db.Integer,primary_key=True)
post_type_id = db.Column(db.Integer)
region_id = db.Column(db.Integer)
count = db.Column(db.Integer)
date = db.Column(db.DateTime,nullable=True)
def __init__(self,count,post_type_id,region_id,date):
self.count = count
self.date = date
self.region_id = region_id
self.post_type_id = post_type_id
def __repr__(self):
return '<Count %r>' % self.count
class PostType(db.Model):
id = db.Column(db.Integer,primary_key=True)
short = db.Column(db.String(10))
name = db.Column(db.String(200), nullable=True)
posts = db.relationship('Post',backref='post_type',lazy="dynamic")
def __init__(self,short):
self.short = short
def __repr__(self):
return '<Type %r>' % self.short
region_to_posts = db.Table('region_to_posts',
db.Column('region_id', db.Integer, db.ForeignKey('region.id')),
db.Column('post_id', db.Integer, db.ForeignKey('post.id'))
)
region_to_parent = db.Table('region_to_parent',
db.Column('region_id',db.Integer,db.ForeignKey('region.id')),
db.Column('parent_id',db.Integer,db.ForeignKey('region.id'))
)
class Region(db.Model):
id = db.Column(db.Integer, primary_key=True)
short = db.Column(db.String(80))
name = db.Column(db.String(200), nullable=True)
published = db.Column(db.Boolean, nullable=True)
posts = db.relationship('Post',secondary=region_to_posts,backref=db.backref('posts',lazy='dynamic'))
parent_id = db.Column(db.Integer, db.ForeignKey('region.id'))
children = db.relationship("Region",
lazy="joined",
join_depth=2)
def __init__(self,short):
self.short = short
self.published = False
def __repr__(self):
return '<Region %r>' % self.short
class Post(db.Model):
id = db.Column(db.Integer, primary_key=True)
post_id = db.Column(db.String(120))
post_date = db.Column(db.DateTime)
remove_date = db.Column(db.DateTime, nullable=True)
title = db.Column(db.String(500))
link = db.Column(db.String(300))
post_type_id = db.Column(db.Integer, db.ForeignKey('post_type.id'))
source = db.relationship('Region',uselist=False ,secondary=region_to_posts, backref=db.backref('source',lazy='dynamic'))
region = db.relationship('Region',uselist=False ,secondary=region_to_posts, backref=db.backref('region',lazy='dynamic'))
section = db.relationship('Region',uselist=False ,secondary=region_to_posts, backref=db.backref('section',lazy='dynamic'))
def __init__(self, post_id, post_date=datetime.datetime.now(), title='test', link='http://sfbay.craigslist.org'):
self.post_id = post_id
self.post_date = post_date
self.title = title
self.link = link
def __repr__(self):
return '<Post %r>' % self.post_id