class VenueGenre(db.Model): __tablename__ = 'venue_genre' genre_id = db.Column(db.Integer, db.ForeignKey('genres.id'), primary_key=True) venue_id = db.Column(db.Integer, db.ForeignKey('venues.id'), primary_key=True) genre = db.relationship('Genre', backref=db.backref('venue_genre', cascade='all, delete-orphan')) venue = db.relationship('Venue', backref=db.backref('venue_genre', cascade='all, delete-orphan')) __table_args__ = (db.UniqueConstraint(genre_id, venue_id), ) @classmethod def delete_old(cls, venue_id, genres): venues_to_delete = db.session.query(cls).filter_by( venue_id=venue_id).filter(cls.genre_id.notin_(genres)) venues_to_delete.delete(synchronize_session=False) @classmethod def get_genres_ids(cls, venue_id): results = cls.query.filter_by(venue_id=venue_id).all() return [str(result.genre_id) for result in results] def __repr__(self): return f'<VenreGenre venue {self.venue_id} genre {self.genre_id}>'
class searchAdConfirmMoney(db.Model, BaseModelMixin): __tablename__ = 'searchad_bra_client_order_confirm_money' id = db.Column(db.Integer, primary_key=True) client_order_id = db.Column( db.Integer, db.ForeignKey('searchAd_bra_client_order.id')) # 客户合同 client_order = db.relationship( 'searchAdClientOrder', backref=db.backref('searchad_confirm_client_order', lazy='dynamic')) order_id = db.Column( db.Integer, db.ForeignKey('searchAd_bra_order.id')) # 客户合同 order = db.relationship( 'searchAdOrder', backref=db.backref('searchad_confirm_order', lazy='dynamic')) money = db.Column(db.Float()) rebate = db.Column(db.Float()) year = db.Column(db.Integer) Q = db.Column(db.String(2)) create_time = db.Column(db.DateTime) __mapper_args__ = {'order_by': year.desc()} def __init__(self, client_order, year, Q, order, money=0.0, rebate=0.0, create_time=None): self.client_order = client_order self.order = order self.money = money self.rebate = rebate self.year = year self.Q = Q self.create_time = create_time or datetime.date.today() @property def time(self): return str(self.year) + str(self.Q)
class PerformanceUser(db.Model, BaseModelMixin): id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) user = db.relationship('User', backref=db.backref('performance_user', lazy='dynamic')) performance = db.relationship('Performance', backref=db.backref('performance_user_money', lazy='dynamic')) performance_id = db.Column(db.Integer, db.ForeignKey('performance.id')) year = db.Column(db.Integer) q_month = db.Column(db.String(10)) money = db.Column(db.Float) # 销售目标 create_time = db.Column(db.DateTime) __mapper_args__ = {'order_by': create_time.desc()} def __init__(self, user, year, q_month, money, create_time, performance): self.user = user self.year = year self.performance = performance self.q_month = q_month self.money = money self.create_time = create_time or datetime.date.today() @property def status(self): return self.performance.status
class Role(db.Model): ''' 鉴权 ''' __tablename__ = 'db_role' id = db.Column(db.Integer, nullable=False, primary_key=True, index=True, autoincrement=True) role_id = db.Column(db.String(36), index=True, nullable=False, unique=True) name = db.Column(db.String(64), nullable=False, unique=True) mark = db.Column(db.String(64), nullable=False, unique=True) disable = db.Column(db.Boolean, index=True, default=False) admins = db.relationship('Admin', backref='role') interfaces = db.relationship('Interface', secondary=InterfaceToRole, backref=db.backref('roles', lazy='dynamic'), lazy='dynamic') menus = db.relationship('Menu', secondary=MenuToRole, backref=db.backref('roles', lazy='dynamic'), lazy='dynamic') __table_args__ = (table_args()) def to_json(self): dict = self.__dict__ if "_sa_instance_state" in dict: del dict["_sa_instance_state"] if "role_list" in dict: del dict["role_list"] return dict def __repr__(self): return '<Role %r>' % self.name
class searchAdClientOrderBill(db.Model, BaseModelMixin, CommentMixin): __tablename__ = 'searchad_bra_client_order_bill' id = db.Column(db.Integer, primary_key=True) company = db.Column(db.String(100)) client_id = db.Column(db.Integer, db.ForeignKey('searchAd_client.id')) client = db.relationship('searchAdClient', backref=db.backref('searchad_bra_client_bill', lazy='dynamic')) medium_id = db.Column(db.Integer, db.ForeignKey('searchAd_medium.id')) medium = db.relationship('searchAdMedium', backref=db.backref('searchad_bra_medium_bill', lazy='dynamic')) resource_type = db.Column(db.Integer) # 推广形式 money = db.Column(db.Float(), default=0.0) rebate_money = db.Column(db.Float(), default=0.0) start = db.Column(db.Date) end = db.Column(db.Date) def __init__(self, company, client, medium, resource_type, money, rebate_money, start=None, end=None): self.company = company self.client = client self.medium = medium self.resource_type = resource_type self.money = money or 0.0 self.rebate_money = rebate_money or 0.0 self.start = start or datetime.date.today() self.end = end or datetime.date.today() @property def resource_type_cn(self): return BILL_RESOURCE_TYPE_CN.get(self.resource_type)
class Commission(db.Model, BaseModelMixin): id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) user = db.relationship('User', backref=db.backref('commission_user', lazy='dynamic'), foreign_keys=[user_id]) year = db.Column(db.Integer) rate = db.Column(db.Float) creator_id = db.Column(db.Integer, db.ForeignKey('user.id')) creator = db.relationship('User', backref=db.backref('commission_creator', lazy='dynamic'), foreign_keys=[creator_id]) create_time = db.Column(db.DateTime) __table_args__ = (db.UniqueConstraint('user_id', 'year', name='_commission_user_year'), ) __mapper_args__ = {'order_by': year.desc()} def __init__(self, user, year=None, rate=None, creator=None, create_time=None): self.user = user self.creator = creator self.year = year or datetime.datetime.now().year self.rate = rate or 0.0 self.create_time = datetime.date.today()
class UserGrades(db.Model): __tablename__ = 'user_grades' id = db.Column(db.Integer(), primary_key=True) user_id = db.Column(db.Integer(), db.ForeignKey('user.id')) user = db.relationship("User", backref=db.backref('grades', order_by=id)) assignment_id = db.Column(db.Integer(), db.ForeignKey('assignment.id')) assignment = db.relationship("Assignment", backref=db.backref('grades', order_by=id)) score = db.Column(db.Numeric())
class Poetry(db.Model): __tablename__ = 'poetry' id = db.Column(db.Integer, primary_key=True, autoincrement=True) title = db.Column(db.String(200), nullable=False) create_time = db.Column(db.DateTime, default=datetime.now) content_path = db.Column(db.Text) poet_id = db.Column(db.Integer, db.ForeignKey('poeter.id')) poet = db.relationship('Poeter', backref=db.backref('poetries')) categories = db.relationship('PoetryCategory', secondary=poetry_tag, backref=db.backref('poetries'))
class Note(db.Model): __tablename__ = 'note' id = db.Column(db.Integer, primary_key=True, autoincrement=True) title = db.Column(db.String(300), nullable=False) create_time = db.Column(db.DateTime, nullable=False, default=datetime.now) content_path = db.Column(db.Text) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) user = db.relationship('User', backref=db.backref('notes')) cat_id = db.Column(db.Integer, db.ForeignKey('note_category.id')) category = db.relationship('NoteCategory', backref=db.backref('notes'))
class Pedido(db.Model): __tablename__ = 'pedidos' id = db.Column(db.Integer, primary_key=True) creation_date = db.Column(db.TIMESTAMP, server_default=db.func.current_timestamp(), nullable=False) cliente_id = db.Column(db.Integer, db.ForeignKey('clientes.id', ondelete='CASCADE'), nullable=False) cliente = db.relationship('Cliente', backref=db.backref('clientes', lazy='dynamic')) itens_pedido = db.relationship('ItensPedido', lazy='select', backref=db.backref('itens_pedidos', lazy='joined')) def __init__(self, cliente_id): self.cliente_id = cliente_id
class Deadlines(db.Model): __tablename__ = 'deadlines' id = db.Column(db.Integer(), primary_key=True) assignment_id = db.Column(db.Integer(), db.ForeignKey('assignment.id')) assignment = db.relationship("Assignment", backref=db.backref('deadlines', order_by=id)) section_id = db.Column(db.Integer(), db.ForeignKey('section.id')) section = db.relationship("Section", backref=db.backref('deadlines', order_by=id)) deadline = db.Column(db.DateTime()) acid = db.Column(db.String(255))
class Blog(db.Model): __tablename__ = 'blog' id = db.Column(db.Integer, primary_key=True, autoincrement=True) title = db.Column(db.String(300), nullable=False) create_time = db.Column(db.DateTime, default=datetime.now) url_id = db.Column(db.String(12), nullable=False) content_path = db.Column(db.Text) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) user = db.relationship('User', backref=db.backref('blogs', order_by='Blog.create_time')) cat_id = db.Column(db.Integer, db.ForeignKey('blog_category.id')) category = db.relationship('BlogCategory', backref=db.backref('blogs', order_by='Blog.create_time'))
class Assignment(db.Model): __tablename__ = 'assignment' id = db.Column(db.Integer(), primary_key=True) course_id = db.Column(db.Integer(), db.ForeignKey('course.id')) course = db.relationship("Course", backref=db.backref('assignments', order_by=id)) type_id = db.Column(db.Integer(), db.ForeignKey('assignment_type.id')) type = db.relationship("AssignmentType", backref=db.backref('assignments', order_by=id)) name = db.Column(db.String(255)) points = db.Column(db.Integer()) threshold = db.Column(db.Integer(), default=1) released = db.Column(db.Boolean()) def __repr__(self): return self.name
class searchAdBackMoney(db.Model, BaseModelMixin): __tablename__ = 'searchAd_bra_client_order_back_money' id = db.Column(db.Integer, primary_key=True) client_order_id = db.Column( db.Integer, db.ForeignKey('searchAd_bra_client_order.id')) # 客户合同 client_order = db.relationship( 'searchAdClientOrder', backref=db.backref('backmoneys', lazy='dynamic')) money = db.Column(db.Float()) back_time = db.Column(db.DateTime) create_time = db.Column(db.DateTime) __mapper_args__ = {'order_by': create_time.desc()} def __init__(self, client_order, money=0.0, create_time=None, back_time=None): self.client_order = client_order self.money = money self.create_time = create_time or datetime.date.today() self.back_time = back_time or datetime.date.today() @property def back_time_cn(self): return self.back_time.strftime(DATE_FORMAT) @property def create_time_cn(self): return self.create_time.strftime(DATE_FORMAT) @property def real_back_money_diff_time(self): return (self.back_time.date() - self.client_order.reminde_date).days
class Company(db.Model): __tablename__ = 'kusm10t' idempres = db.Column(db.String, primary_key=True) cdempres = db.Column(db.String) dsempres = db.Column(db.String) dsrfc = db.Column(db.String) dslogo = db.Column(db.String) dtfecini = db.Column(db.DateTime) nuusuari = db.Column(db.Integer) dtfecalt = db.Column(db.DateTime) dtfecbaj = db.Column(db.DateTime) instatus = db.Column(db.String) idusuari = db.Column(db.String, db.ForeignKey('kusm00t.idusuari')) company_user = db.relationship('User', foreign_keys=[idusuari], backref=db.backref('user', lazy='dynamic')) def __init__(self, codigo, empresa, rfc, logo, fecha, usuarios, alta, baja, estatus, id_usuario): self.cdempres = codigo self.dsempres = empresa self.dsrfc = rfc self.dslogo = logo self.dtfecini = fecha self.nuusuari = usuarios self.dtfecalt = alta self.dtfecbaj = baja self.instatus = estatus self.idusuari = id_usuario def __repr__(self): return '<Company %r>' % self.dsempres
class Document(db.Model): __tablename__ = 'kdem10t' iddocele = db.Column(db.String, primary_key=True) cddocele = db.Column(db.String) dtfecapl = db.Column(db.DateTime) iningegr = db.Column(db.String) dbimport = db.Column(db.Float) intipdoc = db.Column(db.String) dtfecalt = db.Column(db.DateTime) dtfecbaj = db.Column(db.DateTime) idempres = db.Column(db.String, db.ForeignKey('kusm10t.idempres')) document_company = db.relationship('Company', foreign_keys=[idempres], backref=db.backref('companies', lazy='dynamic')) def __init__(self, codigo, fecha, tipo, importe, tipoDocumento, alta, baja, id_empresa): self.cddocele = codigo self.dtfecapl = fecha self.iningegr = tipo self.dbimport = importe self.intipdoc = tipoDocumento self.dtfecalt = alta self.dtfecbaj = baja self.idempres = id_empresa def __repr__(self): return '<Document %r>' % self.dbimport
class Problems(db.Model): __tablename__ = 'problems' id = db.Column(db.Integer(), primary_key=True) assignment_id = db.Column(db.Integer(), db.ForeignKey('assignment.id')) assignment = db.relationship("Assignment", backref=db.backref('problems', order_by=id)) acid = db.Column(db.String(255))
class Performance(db.Model, BaseModelMixin): id = db.Column(db.Integer, primary_key=True) creator_id = db.Column(db.Integer, db.ForeignKey('user.id')) creator = db.relationship('User', backref=db.backref('performance_creator', lazy='dynamic')) status = db.Column(db.Integer) year = db.Column(db.Integer) q_month = db.Column(db.String(10)) t_money = db.Column(db.Float) # 区域销售目标总计 location = db.Column(db.Integer) create_time = db.Column(db.DateTime) __mapper_args__ = {'order_by': create_time.desc()} __table_args__ = (db.UniqueConstraint( 'location', 'year', 'q_month', name='_performance_location_year_q'), ) def __init__(self, creator, year, q_month, t_money, location, create_time=None, status=None): self.creator = creator self.year = year self.q_month = q_month self.t_money = t_money self.location = location self.create_time = create_time or datetime.date.today() self.status = status or PER_STATUS_NEW @property def location_cn(self): return TEAM_LOCATION_CN[self.location]
class Message(db.Model): id = db.Column(db.Integer, primary_key=True) content = db.Column(db.String(128)) sender_id = db.Column(db.Integer, db.ForeignKey('messages_component.id')) sender = db.relationship('MessagesComponent', backref='sent_messages', foreign_keys=[sender_id]) recipients = db.relationship('MessagesComponent', backref=db.backref('messages', lazy='dynamic'), secondary=recipients_table) def __init__(self, content='', sender=None, recipients=None): self.content = content self.sender = sender self.recipients = recipients or [] @property def sender_name(self): return getattr(self.sender, 'name', "DM") def __serialize__(self): return { 'id': self.id, 'content': self.content, 'sender': self.sender_id, 'recipients': [recipient.id for recipient in self.recipients] }
class Menu(db.Model): ''' 菜单 ''' __tablename__ = 'db_menu' id = db.Column(db.Integer, nullable=False, primary_key=True, index=True, autoincrement=True) menu_id = db.Column(db.String(36), index=True, nullable=False, unique=True) pid = db.Column(db.String(36), nullable=False, index=True, default='0') name = db.Column(db.String(64), index=True, nullable=False, unique=True) title = db.Column(db.String(64), nullable=False, unique=True) path = db.Column(db.String(255), nullable=False, unique=True) icon = db.Column(db.String(255), nullable=False) mark = db.Column(db.String(255), nullable=False, unique=True) component = db.Column(db.String(255), nullable=False) componentPath = db.Column(db.String(255), nullable=False) cache = db.Column(db.Boolean, index=True, default=True) sort = db.Column(db.SmallInteger, index=True, default=1) disable = db.Column(db.Boolean, index=True, default=False) interfaces = db.relationship('Interface', secondary=InterfaceToMenu, backref=db.backref('menus', lazy='dynamic'), lazy='dynamic') __table_args__ = (table_args()) def to_json(self): dict = self.__dict__ if "_sa_instance_state" in dict: del dict["_sa_instance_state"] return dict def __repr__(self): return '<Menu %r>' % self.title
class searchAdBackInvoiceRebate(db.Model, BaseModelMixin): __tablename__ = 'searchAd_bra_client_order_back_invoice_rebate' id = db.Column(db.Integer, primary_key=True) client_order_id = db.Column( db.Integer, db.ForeignKey('searchAd_bra_client_order.id')) # 客户合同 client_order = db.relationship( 'searchAdClientOrder', backref=db.backref('backinvoicerebates', lazy='dynamic')) num = db.Column(db.String(100)) # 发票号 money = db.Column(db.Float()) back_time = db.Column(db.DateTime) create_time = db.Column(db.DateTime) __mapper_args__ = {'order_by': create_time.desc()} def __init__(self, client_order, num='', money=0.0, create_time=None, back_time=None): self.client_order = client_order self.num = num self.money = money self.create_time = create_time or datetime.date.today() self.back_time = back_time or datetime.date.today() @property def back_time_cn(self): return self.back_time.strftime(DATE_FORMAT) @property def create_time_cn(self): return self.create_time.strftime(DATE_FORMAT)
class Post(db.Model): id = db.Column(db.Integer, primary_key=True) caption = db.Column(db.String(80), nullable=False) foto = db.Column(db.String(120), nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) users = db.relationship('User', backref='user') userlikes = db.relationship('User', secondary=likes, backref=db.backref('likes', lazy='dynamic')) # UserComment = db.relationship('User', secondary=Comments, # backref=db.backref('Comment', lazy='dynamic')) UserComment = db.relationship('Comment') created_date = db.Column(db.DateTime, default=datetime.now, nullable=True) def __repr__(self): return '<Post %r %r>' % (self.id, self.caption) def data(self, a): return { "id": self.id, "caption": self.caption, "foto": self.foto, "users": self.users.username, "totallike": len(self.userlikes), "userlikes": checkdata(a, self.userlikes) }
class ItensPedido(db.Model): __tablename__ = 'itens_pedido' id = db.Column(db.Integer, primary_key=True) produto_id = db.Column(db.Integer, db.ForeignKey('produtos.id', ondelete='CASCADE'), nullable=False) produto = db.relationship('Produto', backref=db.backref('produtos', lazy='dynamic')) preco_unitario = db.Column(db.DECIMAL(18, 2), nullable=False) quantidade = db.Column(db.Integer, nullable=False) rentabilidade = db.Column(db.String, nullable=False) pedidos_id = db.Column(db.Integer, db.ForeignKey('pedidos.id', ondelete='CASCADE'), nullable=False) pedido = db.relationship('Pedido', backref=db.backref('pedidos', lazy='dynamic')) def __init__(self, produto_id, preco_unitario, quantidade, rentabilidade, pedidos_id): self.produto_id = produto_id self.preco_unitario = preco_unitario self.quantidade = quantidade self.rentabilidade = rentabilidade self.pedidos_id = pedidos_id
class Inventory(db.Model): __tablename__ = 'inventorys' id = db.Column(db.Integer, primary_key=True) deviceID = db.Column(db.Integer, db.ForeignKey('devices.id', ondelete="CASCADE"), nullable=False) device = db.relationship('Device', backref='inventorys') price = db.Column(db.Float, nullable=True) description = db.Column(db.String(2500), nullable=True) owners = db.relationship('User', secondary = "has_owner", backref = db.backref("inventorys")) instances = db.relationship('Instance', cascade="all, delete-orphan", backref = db.backref("inventorys", single_parent=True, cascade="all")) group_id = db.Column(db.Integer, db.ForeignKey('groups.id'), nullable=True) group = db.relationship('Group', backref=db.backref('items', single_parent=True, cascade="all")) def updateFromSchema(self, new): self.device = new.device self.owners = new.owners self.group = new.group self.description = new.description
class Book(db.Model): __tablename__ = 'book' id = db.Column(db.Integer, primary_key=True, autoincrement=True) title = db.Column(db.String(100), nullable=False) title_desc = db.Column(db.String(100), nullable=False, default=title) imagePath = db.Column(db.Text) mdNotePath = db.Column(db.Text) rating = db.Column(db.Integer, nullable=False, default=3) finish_date = db.Column(db.Text, default=str(time.strftime("%Y-%m-%d"))) one_sentence = db.Column(db.Text) eBookPath = db.Column(db.Text) likes = db.Column(db.Integer, nullable=False, default=1) display = db.Column(db.Integer, nullable=False, default=1) author_id = db.Column(db.Integer, db.ForeignKey('book_author.id')) year_id = db.Column(db.Integer, db.ForeignKey('book_year.year')) author = db.relationship('Author', backref=db.backref('books')) year = db.relationship('Year', backref=db.backref('books'))
class searchAdAgentRebate(db.Model, BaseModelMixin): __tablename__ = 'searchAd_bra_agent_rebate' id = db.Column(db.Integer, primary_key=True) agent_id = db.Column(db.Integer, db.ForeignKey('searchAd_agent.id')) # 代理公司id agent = db.relationship('searchAdAgent', backref=db.backref('agentrebate', lazy='dynamic')) inad_rebate = db.Column(db.Float) douban_rebate = db.Column(db.Float) year = db.Column(db.Date) creator_id = db.Column(db.Integer, db.ForeignKey('user.id')) creator = db.relationship('User', backref=db.backref( 'searchAd_created_agent_rebate', lazy='dynamic')) create_time = db.Column(db.DateTime) # 添加时间 __table_args__ = (db.UniqueConstraint( 'agent_id', 'year', name='_searchAd_agent_rebate_year'), ) __mapper_args__ = {'order_by': create_time.desc()} def __init__(self, agent, inad_rebate=0.0, douban_rebate=0.0, year=None, creator=None, create_time=None): self.agent = agent self.inad_rebate = inad_rebate self.douban_rebate = douban_rebate self.year = year or datetime.date.tody() self.creator = creator self.create_time = create_time or datetime.datetime.now() def __repr__(self): return '<searchAdAgentRebate %s>' % (self.id) @property def create_time_cn(self): return self.create_time.strftime("%Y-%m-%d")
class IncomingFax(db.Model): __tablename__ = 'incoming_fax' id = Column(BigInteger, primary_key=True) account_id = Column(BigInteger, ForeignKey('account.id')) external_id = Column(BigInteger) account = db.relationship('Account', backref=db.backref('incoming_faxes', order_by=id)) access_key = Column(String(64), unique=True, index=True) num_pages = Column(Integer) cost = Column(Float) from_number = Column(String(32)) to_number = Column(String(32)) hosted_url = Column(String(255)) data_deleted = Column(SmallInteger, default=0) create_date = Column(DateTime) mod_date = Column(DateTime) def __init__(self, account_id, external_id, num_pages, cost, from_number, to_number): self.create_date = datetime.now() self.account_id = account_id self.external_id = external_id self.num_pages = num_pages self.cost = cost self.from_number = from_number self.to_number = to_number self.access_key = random_hash( "%s%s%s%s%s" % (from_number, to_number, cost, num_pages, account_id)) def public_data(self): """ Returns a dictionary of fields that are safe to display to the end user. """ data = { 'id': self.id, 'access_key': self.access_key, 'num_pages': self.num_pages, 'cost': self.cost, 'from_number': self.from_number, 'to_number': self.to_number, 'data_deleted': self.data_deleted, 'create_date': self.create_date, 'mod_date': self.mod_date } return data def __repr__(self): return "<IncomingFax(id='%s', account_id='%s', from_number='%s')>" % \ (self.id, self.account_id, self.from_number)
class Post(db.Model): id = db.Column(db.Integer, primary_key=True) body = db.Column(db.Text) timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) categorys = db.relationship('Category', secondary=categorys, backref=db.backref('posts', lazy='dynamic')) def __repr__(self): return '<Post {}>'.format(self.body)
class searchAdClientOrderExecutiveReport(db.Model, BaseModelMixin): __tablename__ = 'searchAd_bra_client_order_executive_report' id = db.Column(db.Integer, primary_key=True) client_order_id = db.Column( db.Integer, db.ForeignKey('searchAd_bra_client_order.id')) # 客户合同 client_order = db.relationship( 'searchAdClientOrder', backref=db.backref('executive_reports', lazy='dynamic')) money = db.Column(db.Float()) month_day = db.Column(db.DateTime) days = db.Column(db.Integer) create_time = db.Column(db.DateTime) # 合同文件打包 order_json = db.Column(db.Text(), default=json.dumps({})) status = db.Column(db.Integer, index=True) contract_status = db.Column(db.Integer, index=True) __table_args__ = (db.UniqueConstraint( 'client_order_id', 'month_day', name='_searchAd_client_order_month_day'),) __mapper_args__ = {'order_by': create_time.desc()} def __init__(self, client_order, money=0, month_day=None, days=0, create_time=None): self.client_order = client_order self.money = money self.month_day = month_day or datetime.date.today() self.days = days self.create_time = create_time or datetime.date.today() # 合同文件打包 self.status = client_order.status self.contract_status = client_order.contract_status # 获取相应合同字段 dict_order = {} dict_order['client_name'] = client_order.client.name dict_order['agent_name'] = client_order.agent.name dict_order['contract'] = client_order.contract dict_order['campaign'] = client_order.campaign dict_order['industry_cn'] = client_order.client.industry_cn dict_order['locations'] = client_order.locations dict_order['sales'] = [ {'id': k.id, 'name': k.name, 'location': k.team.location}for k in client_order.direct_sales] dict_order['salers_ids'] = [k['id'] for k in dict_order['sales']] dict_order['get_saler_leaders'] = [ k.id for k in client_order.get_saler_leaders()] dict_order['resource_type_cn'] = client_order.resource_type_cn dict_order['operater_users'] = [ {'id': k.id, 'name': k.name}for k in client_order.operater_users] dict_order['client_start'] = client_order.client_start.strftime( '%Y-%m-%d') dict_order['client_end'] = client_order.client_end.strftime('%Y-%m-%d') self.order_json = json.dumps(dict_order) @property def month_cn(self): return self.month_day.strftime('%Y-%m') + u'月'
class User(db.Model): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(80), nullable=False) password = db.Column(db.String(120), nullable=False) posts = db.relationship('Post', backref='post') prodlikes = db.relationship('Post', secondary=likes, backref=db.backref('likes', lazy='dynamic')) UserComment = db.relationship('Comment') # comment=db.relationship('Comment',backref='Comment') def __repr__(self): return '<User %r %r>' % (self.id, self.username)