diff options
author | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2017-02-13 15:27:13 +0100 |
---|---|---|
committer | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2017-02-13 15:27:13 +0100 |
commit | 879427aa740f399aecd31c0e12909e6f39705f5e (patch) | |
tree | 5bb2d792e7211c763db550eaf8f0c676e37aa25a /src/web/models/tag.py | |
parent | Merge branch 'master' of github.com:newspipe/newspipe into bookmark (diff) | |
download | newspipe-879427aa740f399aecd31c0e12909e6f39705f5e.tar.gz newspipe-879427aa740f399aecd31c0e12909e6f39705f5e.tar.bz2 newspipe-879427aa740f399aecd31c0e12909e6f39705f5e.zip |
wip
Diffstat (limited to 'src/web/models/tag.py')
-rw-r--r-- | src/web/models/tag.py | 50 |
1 files changed, 17 insertions, 33 deletions
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 |