~cedric/newspipe

0fa1a1c363aaf934a9ce80ee8b255cf8b840901e — Cédric Bonhomme 4 years ago f7b6902
We will finally have a table for tags of articles and tags of bookmarks.
3 files changed, 12 insertions(+), 24 deletions(-)

M src/web/models/article.py
M src/web/models/bookmark.py
M src/web/models/tag.py
M src/web/models/article.py => src/web/models/article.py +0 -2
@@ 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)

M src/web/models/bookmark.py => src/web/models/bookmark.py +4 -12
@@ 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')



M src/web/models/tag.py => src/web/models/tag.py +8 -10
@@ 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