-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodels.py
More file actions
74 lines (57 loc) · 2.19 KB
/
models.py
File metadata and controls
74 lines (57 loc) · 2.19 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
from datetime import datetime
from config import db
class Users(db.Model):
'__users__'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.TEXT(80))
username = db.Column(db.TEXT(80), unique=True)
email = db.Column(db.TEXT(120), unique=True)
password = db.Column(db.TEXT(120))
comments = db.relationship('Comments', backref='users', lazy='dynamic')
@staticmethod
def get_comments():
return Comments.query.filter_by(user_id=users.id).order_by(Comments.timestamp.desc())
def __init__(self, name, username, email, password):
self.name = name
self.username = username
self.email = email
self.password = password
def __repr__(self):
return '<Users {}'.format(self.username)
class Videos(db.Model):
'__videos__'
id = db.Column(db.Integer, primary_key=True, autoincrement=True, unique=True)
title = db.Column(db.TEXT, unique=True)
link = db.Column(db.String)
author = db.Column(db.TEXT)
# likes = db.Column(db.Integer)
create_date = db.Column(db.TIMESTAMP, default=datetime.now)
comments = db.relationship('Comments', backref='videos', lazy='dynamic')
# @staticmethod
# def like_video():
# Videos.likes += 1
# @staticmethod
# def dislike_video():
# Videos.likes -= 1
@staticmethod
def get_comments():
return Comments.query.filter_by(video_id=Videos.id).order_by(Comments.timestamp.desc())
def __init__(self, title, link, author):
self.title = title
self.link = link
self.author = author
def __repr__(self):
return '<Videos {}>'.format(self.title)
class Comments(db.Model):
'__comments__'
id = db.Column(db.Integer, primary_key=True, autoincrement=True, unique=True)
body = db.Column(db.String(140))
timestamp = db.Column(db.TIMESTAMP, default=datetime.now)
video_id = db.Column(db.Integer, db.ForeignKey('videos.id'))
user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
def __init__(self, body, video_id, user_id):
self.body = body
self.video_id = video_id
self.user_id = user_id
def __repr__(self):
return 'Comments {}>'.format(self.body)