-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
44 lines (36 loc) · 1.48 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
from notlar import db
from flask_login import UserMixin
class User(db.Model, UserMixin):
__tablename__ = 'users'
id = db.Column(db.Integer, primary_key=True)
email = db.Column(db.String(120), unique=True, nullable=False)
username = db.Column(db.String(80), unique=True, nullable=False)
password = db.Column(db.String(255), nullable=False)
name = db.Column(db.String(80))
last_name = db.Column(db.String(80))
phone_number = db.Column(db.String(20))
telegram_user = db.Column(db.String(80))
profile_picture = db.Column(db.String(255))
notes = db.relationship('Note', backref='user', lazy=True)
# Methods required by flask-login module
# It will be handled by the login_required decorator
def get_id(self):
return str(self.id)
@property
def is_active(self):
return True
@property
def is_authenticated(self):
return True
@property
def is_anonymous(self):
return True
class Note(db.Model):
__tablename__ = 'notes'
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(255), nullable=False)
text = db.Column(db.String(1000), nullable=False)
color = db.Column(db.String(7), nullable=False)
user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
created_at = db.Column(db.DateTime, default=db.func.current_timestamp())
updated_at = db.Column(db.DateTime, default=db.func.current_timestamp(), onupdate=db.func.current_timestamp())