-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
29 lines (25 loc) · 1020 Bytes
/
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
from app import db
from sqlalchemy import UniqueConstraint
# This class will hold all files owned by the user
# If the user is not logged in, he will not be able to save his work.
class Files(db.Model):
__tablename__ = "files"
id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer)
file_name = db.Column(db.String)
file_content = db.Column(db.String)
tags = db.Column(db.String)
__table_args__ = (UniqueConstraint('user_id', 'file_name', name='unique_user_file'),)
def __init__(self, user_id, file_name, file_content, tags):
self.user_id = user_id
self.file_name = file_name
self.file_content = file_content
self.tags = tags
def serialize(self):
return {
'id': self.id,
'user_id': self.user_id,
'file_name': self.file_name,
'file_content': self.file_content,
'tags': self.tags
}