From 219b22e34a72e209d77b7e5a9b569a42f0bd8c7b Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Tue, 16 Apr 2024 21:23:19 +1200 Subject: [PATCH] migration post one language --- app/models.py | 52 +++++++++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/app/models.py b/app/models.py index 6a174cff..07913593 100644 --- a/app/models.py +++ b/app/models.py @@ -169,6 +169,28 @@ class ChatMessage(db.Model): sender = db.relationship('User', foreign_keys=[sender_id]) +class Tag(db.Model): + id = db.Column(db.Integer, primary_key=True) + name = db.Column(db.String(256)) + + +class Language(db.Model): + id = db.Column(db.Integer, primary_key=True) + code = db.Column(db.String(5), index=True) + name = db.Column(db.String(50)) + + +community_language = db.Table('community_language', db.Column('community_id', db.Integer, db.ForeignKey('community.id')), + db.Column('language_id', db.Integer, db.ForeignKey('language.id')), + db.PrimaryKeyConstraint('community_id', 'language_id') + ) + +post_tag = db.Table('post_tag', db.Column('post_id', db.Integer, db.ForeignKey('post.id')), + db.Column('tag_id', db.Integer, db.ForeignKey('tag.id')), + db.PrimaryKeyConstraint('post_id', 'tag_id') + ) + + class File(db.Model): id = db.Column(db.Integer, primary_key=True) file_path = db.Column(db.String(255)) @@ -365,6 +387,7 @@ class Community(db.Model): replies = db.relationship('PostReply', lazy='dynamic', cascade="all, delete-orphan") icon = db.relationship('File', foreign_keys=[icon_id], single_parent=True, backref='community', cascade="all, delete-orphan") image = db.relationship('File', foreign_keys=[image_id], single_parent=True, cascade="all, delete-orphan") + languages = db.relationship('Language', lazy='dynamic', secondary=community_language, backref=db.backref('communities', lazy='dynamic')) @cache.memoize(timeout=500) def icon_image(self, size='default') -> str: @@ -895,7 +918,9 @@ class Post(db.Model): language = db.Column(db.String(10)) edited_at = db.Column(db.DateTime) reports = db.Column(db.Integer, default=0) # how many times this post has been reported. Set to -1 to ignore reports + language_id = db.Column(db.Integer, index=True) cross_posts = db.Column(MutableList.as_mutable(ARRAY(db.Integer))) + tags = db.relationship('Tag', lazy='dynamic', secondary=post_tag, backref=db.backref('posts', lazy='dynamic')) ap_id = db.Column(db.String(255), index=True) ap_create_id = db.Column(db.String(100)) @@ -1294,33 +1319,6 @@ class Site(db.Model): return User.query.filter_by(deleted=False, banned=False).join(user_role).filter(user_role.c.role_id == 4).all() -class Tag(db.Model): - id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(256)) - - -class Language(db.Model): - id = db.Column(db.Integer, primary_key=True) - code = db.Column(db.String(5), index=True) - name = db.Column(db.String(50)) - - -post_language = db.Table('post_language', db.Column('post_id', db.Integer, db.ForeignKey('post.id')), - db.Column('language_id', db.Integer, db.ForeignKey('language.id')), - db.PrimaryKeyConstraint('post_id', 'language_id') - ) - -community_language = db.Table('community_language', db.Column('community_id', db.Integer, db.ForeignKey('community.id')), - db.Column('language_id', db.Integer, db.ForeignKey('language.id')), - db.PrimaryKeyConstraint('community_id', 'language_id') - ) - -post_tag = db.Table('post_tag', db.Column('post_id', db.Integer, db.ForeignKey('post.id')), - db.Column('tag_id', db.Integer, db.ForeignKey('tag.id')), - db.PrimaryKeyConstraint('post_id', 'tag_id') - ) - - @login.user_loader def load_user(id): return User.query.get(int(id))