From 0fa1a1c363aaf934a9ce80ee8b255cf8b840901e Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Fri, 21 Apr 2017 23:09:42 +0200 Subject: We will finally have a table for tags of articles and tags of bookmarks. --- src/web/models/article.py | 2 -- src/web/models/bookmark.py | 16 ++++------------ src/web/models/tag.py | 18 ++++++++---------- 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/src/web/models/article.py b/src/web/models/article.py index 6245b10e..f5ef619e 100644 --- a/src/web/models/article.py +++ b/src/web/models/article.py @@ -34,8 +34,6 @@ from sqlalchemy.ext.associationproxy import association_proxy from web.models.right_mixin import RightMixin - - class Article(db.Model, RightMixin): "Represent an article from a feed." id = db.Column(db.Integer(), primary_key=True) diff --git a/src/web/models/bookmark.py b/src/web/models/bookmark.py index 6101a5f0..891c3eda 100644 --- a/src/web/models/bookmark.py +++ b/src/web/models/bookmark.py @@ -34,13 +34,6 @@ from sqlalchemy.ext.associationproxy import association_proxy from web.models.right_mixin import RightMixin -bookmarktags_table = db.Table('bookmarktags', db.metadata, - db.Column('bookmark_id', db.Integer, db.ForeignKey("bookmark.id"), - primary_key=True), - db.Column('tag_text', db.String, db.ForeignKey("BookmarkTag.text"), - primary_key=True) -) - class Bookmark(db.Model, RightMixin): """ Represent a bookmark. @@ -55,11 +48,10 @@ class Bookmark(db.Model, RightMixin): user_id = db.Column(db.Integer(), db.ForeignKey('user.id')) # relationships - tag_objs = db.relationship("BookmarkTag", secondary=lambda: bookmarktags_table) - # tag_objs = db.relationship('BookmarkTag', back_populates='bookmark', - # cascade='all,delete-orphan', - # lazy=False, - # foreign_keys='[BookmarkTag.bookmark_id]') + tag_objs = db.relationship('BookmarkTag', back_populates='bookmark', + cascade='all,delete-orphan', + lazy=False, + foreign_keys='[BookmarkTag.bookmark_id]') tags = association_proxy('tag_objs', 'text') diff --git a/src/web/models/tag.py b/src/web/models/tag.py index c23d15ea..70430fa6 100644 --- a/src/web/models/tag.py +++ b/src/web/models/tag.py @@ -6,6 +6,7 @@ from bootstrap import db class ArticleTag(db.Model): text = db.Column(db.String, primary_key=True, unique=False) + # user_id = db.Column(db.Integer(), db.ForeignKey('user.id')) # foreign keys article_id = db.Column(db.Integer, db.ForeignKey('article.id', ondelete='CASCADE'), @@ -13,26 +14,23 @@ class ArticleTag(db.Model): # relationships article = db.relationship('Article', back_populates='tag_objs', - foreign_keys=[article_id]) + foreign_keys=[article_id]) def __init__(self, text): self.text = text class BookmarkTag(db.Model): - __tablename__ = 'BookmarkTag' - #id = db.Column(db.Integer, primary_key=True) - text = db.Column(db.String, primary_key=True) + text = db.Column(db.String, primary_key=True, unique=False) + # user_id = db.Column(db.Integer(), db.ForeignKey('user.id')) # foreign keys - # bookmark_id = db.Column(db.Integer, db.ForeignKey('bookmark.id', ondelete='CASCADE'), - # primary_key=True) + bookmark_id = db.Column(db.Integer, db.ForeignKey('bookmark.id', ondelete='CASCADE'), + primary_key=True) # relationships - # bookmark = db.relationship('Bookmark', back_populates='tag_objs', - # single_parent=True, - # cascade="all, delete-orphan", - # foreign_keys=[bookmark_id]) + bookmark = db.relationship('Bookmark', back_populates='tag_objs', + foreign_keys=[bookmark_id]) def __init__(self, text): self.text = text -- cgit