-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
32 lines (22 loc) · 801 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
30
31
32
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from app import db
posts_tags_table = db.Table(
'posts_tags_table', db.Model.metadata,
db.Column('post_id', db.String, db.ForeignKey('post.id')),
db.Column('tag_id', db.Integer, db.ForeignKey('tag.id'))
)
class Post(db.Model):
__tablename__ = 'post'
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
title = db.Column(db.String(250))
tags = db.relationship('Tag', secondary=posts_tags_table)
def __str__(self):
return self.title
class Tag(db.Model):
__tablename__ = 'tag'
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
name = db.Column(db.String)
posts = db.relationship('Post', secondary=posts_tags_table)
def __str__(self):
return self.name