-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
107 lines (91 loc) · 3.41 KB
/
Copy pathmodels.py
File metadata and controls
107 lines (91 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
#!/usr/bin/python
# -*- coding: utf-8 -*-
from app import db
from werkzeug.security import generate_password_hash, check_password_hash
class User(db.Model):
__tablename__ = 'users'
id = db.Column(db.Integer, primary_key=True, nullable=False)
username = db.Column(db.String(25), index=True, unique=True,
nullable=False)
password_hash = db.Column(db.String(128), nullable=False)
email = db.Column(db.String(120), index=True, unique=True,
nullable=False)
def __init__(
self,
username,
password,
email,
):
self.username = username
self.password_hash = generate_password_hash(password)
self.email = email
def __repr__(self):
return '<User %r>' % self.username
def verify_password(self, password):
return check_password_hash(self.password_hash, password)
class news_data(db.Model):
__tablename__ = 'news'
id = db.Column(db.INTEGER, primary_key=True, nullable=False)
author = db.Column(db.String(5012), nullable=True)
title = db.Column(db.String(5012), nullable=False)
desc = db.Column(db.String(5012), nullable=True)
url = db.Column(db.String(5012), nullable=True)
urlToImage = db.Column(db.String(5012), nullable=True)
publishedAt = db.Column(db.String(5012), nullable=True)
downvotes = db.Column(db.INTEGER, nullable=True)
upvotes = db.Column(db.INTEGER, nullable=True)
category = db.Column(db.String(5012),nullable=True)
def __init__(self, author, title, desc, url, urlToImage, publishedAt, category):
self.author = author
self.title = title
self.desc = desc
self.url = url
self.urlToImage = urlToImage
self.publishedAt = publishedAt
self.category = category
def upvote(self):
if not self.upvotes:
self.upvotes = 1
else:
self.upvotes +=1
def downvote(self):
if not self.downvotes:
self.downvotes = 1
else:
self.downvotes +=1
class user_vote_data(db.Model):
__tablename__ = 'vote_data'
id = db.Column(db.INTEGER, primary_key=True, nullable=False)
downvotes = db.Column(db.INTEGER, nullable=True)
upvotes = db.Column(db.INTEGER, nullable=True)
user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
news_id = db.Column(db.Integer, db.ForeignKey('news.id'))
def __init__(self,upvote=None,downvote=None,user_id=None,news_id=None):
self.downvote = downvote
self.upvotes = upvote
self.user_id = user_id
self.news_id = news_id
class Post(db.Model):
__tablename__="news_db"
id = db.Column(db.INTEGER, primary_key=True, nullable=False)
user_id = db.Column(db.String(255))
upvotes = db.Column(db.String(255))
downvotes = db.Column(db.Integer)
news_id = db.Column(db.String(255))
check_votes = db.Column(db.String(255))
def __init__(self, user_id=None, upvotes=None, downvotes=None, news_id=None,check_votes=None):
self.user_id= user_id
self.news_id = news_id
self.upvotes = upvotes
self.downvotes = downvotes
self.check_votes = check_votes
def upvote(self):
if not self.upvotes:
self.upvotes = 1
else:
self.upvotes +=1
def downvote(self):
if not self.downvotes:
self.downvotes = 1
else:
self.downvotes +=1