-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
26 lines (20 loc) · 940 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
from flask_sqlalchemy import SQLAlchemy
from mistune import markdown
db = SQLAlchemy()
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(80), unique=True, nullable=False)
password = db.Column(db.String(200))
created_at = db.Column(db.DateTime, server_default=db.func.now())
updated_at = db.Column(db.DateTime, server_default=db.func.now(), server_onupdate=db.func.now())
notes = db.relationship('Note', backref='author', lazy=True)
class Note(db.Model):
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(200))
body = db.Column(db.Text)
created_at = db.Column(db.DateTime, server_default=db.func.now())
updated_at = db.Column(db.DateTime, server_default=db.func.now(), server_onupdate=db.func.now())
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
@property
def body_html(self):
return markdown(self.body)