from sqlalchemy import Column, Integer, String, ForeignKey, Enum, Date, Float from sqlalchemy.dialects.postgresql import UUID from datetime import datetime import re from app.models.base import Base, db from app.models.user import User campaign_editorial_topic = db.Table( 'campaign_editorial_topic', Column('campaign_id', Integer, ForeignKey('campaign.campaign_id')), Column('editorial_topic_id', Integer, ForeignKey('editorial_topic.editorial_topic_id')), ) class Campaign(Base): __tablename__ = 'campaign' index = Column(Integer, primary_key=True, autoincrement=True) # TODO: list campaign table schema here # user_id = Column(UUID) # token = Column(String) campaign_id = Column(Integer, unique=True) campaign_name = Column(String) campaign_obj_type = Column( Enum('私域促活/留存', '私域拉新', '裂变', name='campaign objective type')) campaign_time_start = Column(Date) campaign_time_end = Column(Date) campaign_core_metric_type = Column(String) campaign_core_metric_value = Column(Float) editorial_topics = db.relationship('Editorial_topic',
from app import login_manager from app.models.base import Base, db _Author_ = 'BUPPT' class Permission: AUTHOR = 2 REVIEWER = 4 EDITOR = 8 ADMIN = 16 user_roles = db.Table( 'user_roles', db.Column('user_id', db.Integer, db.ForeignKey("users.id")), db.Column('role_id', db.Integer, db.ForeignKey("roles.id"))) class Role(db.Model): __tablename__ = 'roles' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(64), unique=True) default = db.Column(db.Boolean, default=False, index=True) permissions = db.Column(db.Integer) def __repr__(self): return '<Role id={0}, name={1}>'.format(self.id, self.name) def __init__(self, **kwargs): super(Role, self).__init__(**kwargs)
from sqlalchemy import Column, Integer, String, ForeignKey from sqlalchemy.dialects.postgresql import UUID from app.models.base import Base, db from app.models.campaign import Campaign # If a table exists, create_all will not update the changed table. So you should delete this table first. editorial_topic_tag = db.Table( 'editorial_topic_tag', Column('editorial_topic_id', Integer, ForeignKey('editorial_topic.editorial_topic_id')), Column('tag_index', Integer, ForeignKey('tag.index')), ) editorial_topic_article = db.Table( 'editorial_topic_article', Column('editorial_topic_id', Integer, ForeignKey('editorial_topic.editorial_topic_id')), Column('article_id', Integer, ForeignKey('article.article_id')), ) # user is a keyword for pqsql class Editorial_topic(Base): __tablename__ = 'editorial_topic' index = Column(Integer, primary_key=True, autoincrement=True) # TODO: list campaign table schema here editorial_topic_id = Column(Integer, unique=True) editorial_topic_name = Column(String) editorial_topic_description = Column(String)
from sqlalchemy import Column, Integer, String, ForeignKey from sqlalchemy.dialects.postgresql import UUID from app.models.base import Base, db # from app.models.campaign import Campaign # If a table exists, create_all will not update the changed table. So you should delete this table first. user_campaign = db.Table( 'user_campaign', Column('user_id', Integer, ForeignKey('user_table.user_id')), Column('campaign_id', Integer, ForeignKey('campaign.campaign_id')), ) # user is a keyword for pqsql class User(Base): __tablename__ = 'user_table' index = Column(Integer, primary_key=True, autoincrement=True) # TODO: list campaign table schema here user_id = Column(Integer, unique=True) campaigns = db.relationship('Campaign', secondary=user_campaign, backref=db.backref('users', lazy='dynamic')) def keys(self): self.hide('index') return self.fields @staticmethod def create_user(user_id):
from sqlalchemy import Column, Integer, String, ForeignKey, Float, Text, Date from sqlalchemy.dialects.postgresql import UUID from app.models.base import Base, db from app.models.editorial_topic import Editorial_topic # If a table exists, create_all will not update the changed table. So you should delete this table first. article_tag = db.Table( 'article_tag', Column('article_id', Integer, ForeignKey('article.article_id')), Column('tag_index', Integer, ForeignKey('tag.index')), ) # user is a keyword for pqsql class Article(Base): __tablename__ = 'article' index = Column(Integer, primary_key=True, autoincrement=True) # TODO: list campaign table schema here article_id = Column(Integer, unique=True) article_importance = Column(Float) author = Column(String) source = Column(String) title = Column(String) url = Column(Text) time_created = Column(Date) thumbnail_url = Column(Text) abstract = Column(Text) tags = db.relationship('Tag', secondary=article_tag,