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
|
#! /usr/bin/env python
# -*- coding: utf-8 -*-
from sqlalchemy import Index, ForeignKeyConstraint
from newspipe.bootstrap import db
class ArticleTag(db.Model):
text = db.Column(db.String, primary_key=True, unique=False)
# foreign keys
article_id = db.Column(
db.Integer, db.ForeignKey("article.id", ondelete="CASCADE"), primary_key=True
)
# relationships
article = db.relationship(
"Article", back_populates="tag_objs", foreign_keys=[article_id]
)
def __init__(self, text):
self.text = text
__table_args__ = (
ForeignKeyConstraint([article_id], ['article.id'],
ondelete='CASCADE'),
Index('ix_articletag_aid', article_id),
)
class BookmarkTag(db.Model):
id = db.Column(db.Integer, primary_key=True)
text = db.Column(db.String, unique=False)
# foreign keys
user_id = db.Column(db.Integer, db.ForeignKey("user.id", ondelete="CASCADE"))
bookmark_id = db.Column(
db.Integer, db.ForeignKey("bookmark.id", ondelete="CASCADE")
)
# relationships
bookmark = db.relationship(
"Bookmark",
back_populates="tags",
cascade="all,delete",
foreign_keys=[bookmark_id],
)
# def __init__(self, text, user_id):
# self.text = text
# self.user_id = user_id
|