diff options
Diffstat (limited to 'src/web/models')
-rw-r--r-- | src/web/models/__init__.py | 2 | ||||
-rw-r--r-- | src/web/models/article.py | 8 | ||||
-rw-r--r-- | src/web/models/bookmark.py | 9 | ||||
-rw-r--r-- | src/web/models/tag.py | 50 |
4 files changed, 28 insertions, 41 deletions
diff --git a/src/web/models/__init__.py b/src/web/models/__init__.py index c8fc1aef..229a99e5 100644 --- a/src/web/models/__init__.py +++ b/src/web/models/__init__.py @@ -32,7 +32,7 @@ from .user import User from .article import Article from .icon import Icon from .category import Category -from .tag import Tag +#from .tag import Tag from .tag import BookmarkTag from .tag import ArticleTag from .bookmark import Bookmark diff --git a/src/web/models/article.py b/src/web/models/article.py index 923d6869..6245b10e 100644 --- a/src/web/models/article.py +++ b/src/web/models/article.py @@ -34,6 +34,8 @@ 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) @@ -53,9 +55,9 @@ class Article(db.Model, RightMixin): # relationships tag_objs = db.relationship('ArticleTag', back_populates='article', - cascade='all,delete-orphan', - lazy=False, - foreign_keys='[ArticleTag.article_id]') + cascade='all,delete-orphan', + lazy=False, + foreign_keys='[ArticleTag.article_id]') tags = association_proxy('tag_objs', 'text') # index diff --git a/src/web/models/bookmark.py b/src/web/models/bookmark.py index a796cffa..b62285b7 100644 --- a/src/web/models/bookmark.py +++ b/src/web/models/bookmark.py @@ -34,14 +34,15 @@ from sqlalchemy.ext.associationproxy import association_proxy from web.models.right_mixin import RightMixin + class Bookmark(db.Model, RightMixin): """ Represent a bookmark. """ id = db.Column(db.Integer(), primary_key=True) href = db.Column(db.String(), default="") + title = db.Column(db.String(), default="") description = db.Column(db.String(), default="FR") - extended = db.Column(db.String()) shared = db.Column(db.Boolean(), default=False) to_read = db.Column(db.Boolean(), default=False) time = db.Column(db.DateTime(), default=datetime.utcnow) @@ -49,9 +50,9 @@ class Bookmark(db.Model, RightMixin): # relationships tag_objs = db.relationship('BookmarkTag', back_populates='bookmark', - cascade='all,delete-orphan', - lazy=False, - foreign_keys='[BookmarkTag.bookmark_id]') + 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 d43ce300..28727dbf 100644 --- a/src/web/models/tag.py +++ b/src/web/models/tag.py @@ -1,50 +1,34 @@ #! /usr/bin/env python # -*- coding: utf-8 -*- -from sqlalchemy import Column, ForeignKey, Integer, String -from sqlalchemy.orm import relationship - from bootstrap import db -class Tag(db.Model): - id = db.Column(db.Integer(), primary_key=True) - text = Column(String, unique=False) - obj = db.Column(db.String, default='article') - user_id = db.Column(db.Integer(), db.ForeignKey('user.id'), nullable=False) +class ArticleTag(db.Model): + text = db.Column(db.String, primary_key=True, unique=False) - __mapper_args__ = { - 'polymorphic_on': obj - } + # 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 -class ArticleTag(Tag): - __mapper_args__ = { - 'polymorphic_identity': 'article' - } - id = db.Column(db.Integer, db.ForeignKey('tag.id', ondelete='CASCADE'), - primary_key=True) - - # relationships - article_id = Column(Integer, ForeignKey('article.id', ondelete='CASCADE'), - nullable=False) - article = relationship('Article', back_populates='tag_objs', - foreign_keys=[article_id]) - +class BookmarkTag(db.Model): + text = db.Column(db.String, primary_key=True, unique=False) -class BookmarkTag(Tag): - __mapper_args__ = { - 'polymorphic_identity': 'bookmark' - } - id = db.Column(db.Integer, db.ForeignKey('tag.id', ondelete='CASCADE'), - primary_key=True) + # foreign keys + bookmark_id = db.Column(db.Integer, db.ForeignKey('bookmark.id', ondelete='CASCADE'), + primary_key=True) # relationships - bookmark_id = Column(Integer, ForeignKey('bookmark.id', ondelete='CASCADE'), - nullable=False) - bookmark = relationship('Bookmark', back_populates='tag_objs', + bookmark = db.relationship('Bookmark', back_populates='tag_objs', foreign_keys=[bookmark_id]) + + def __init__(self, text): + self.text = text |