class PhoneType(db.Model): __tablename__ = 'phone_types' id = db.Column(db.Integer, primary_key=True) phoneType = db.Column(db.String(80)) screenTypeId = db.Column(db.Integer, db.ForeignKey('part_types.id')) batteryTypeId = db.Column(db.Integer, db.ForeignKey('part_types.id')) memoryTypeId = db.Column(db.Integer, db.ForeignKey('part_types.id')) description = db.Column(db.String(300)) imagePath = db.Column(db.String(300)) price = db.Column(db.Float) deletedAt = db.Column(db.DateTime) phones = db.relationship('Phone', backref='phone_types', lazy='dynamic') isRecalled = db.Column(db.Boolean) # screenType = db.relationship('PartType', foreign_keys = 'screenTypeId') # batteryType = db.relationship('PartType', foreign_keys = 'batteryTypeId') # memoryType = db.relationship('PartType', foreign_keys = 'memoryTypeId') def __init__(self, phoneType, screenType, batteryType, memoryType, description, imagePath, price): self.phoneType = phoneType self.screenTypeId = screenType self.batteryTypeId = batteryType self.memoryTypeId = memoryType self.description = description self.imagePath = imagePath self.price = price self.deletedAt = None self.isRecalled = False
class Stuff(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(255), nullable=False) detail = db.Column(db.String(10000)) owner_id = db.Column(db.Integer, db.ForeignKey('user.id')) owner = db.relationship('User', backref='stuff_list') address_id = db.Column(db.Integer, db.ForeignKey('address.id')) stuff_address = db.relationship('Address', backref='stuff_list') date = db.Column(db.DateTime, default=datetime.now) stuff_type = db.relationship('StuffType', backref='stuff_list') type_id = db.Column(db.Integer, db.ForeignKey('stufftype.id')) category = db.relationship('Category', backref='stuff_list') category_id = db.Column(db.Integer, db.ForeignKey('category.id')) group_id = db.Column(db.Integer, db.ForeignKey('group.id')) group = db.relationship('Group', backref='stuff_list') approved = db.Column(db.Integer, default=0) status = db.Column(db.Integer, default=1) is_wanted = db.Column(db.Boolean, default=False) created_at = db.Column(db.DateTime, default=datetime.now) def __repr__(self): return "%s" % (self.title) @property def admin_url(self): return "%s/%s/%s" % (app.config['ADMIN_URL'], 'stuff', self.id) @property def edit_url(self): return "%s/%s" % ('edit_stuff', self.id) @property def url(self): return "%s/%s" % ('show_stuff', self.id)
class Biddings(db.Model, UserMixin): petname = db.Column(db.String, db.ForeignKey('pets.petname', ondelete='CASCADE'), primary_key=True, nullable=False) pcontact = db.Column(db.Integer, db.ForeignKey('pets.pcontact', ondelete='CASCADE'), primary_key=True, nullable=False) ccontact = db.Column(db.Integer, db.ForeignKey('users.contact', ondelete='CASCADE'), primary_key=True, nullable=False) startdate = db.Column(db.Date, primary_key=True, nullable=False) enddate = db.Column(db.Date, primary_key=True, nullable=False) paymentmode = db.Column(db.String, nullable=False) deliverymode = db.Column(db.String, nullable=False) status = db.Column(db.String, nullable=False) pcontactrel = db.relationship("Pets", foreign_keys=[pcontact]) petnamerel = db.relationship("Pets", foreign_keys=[petname]) # reviewpetname = db.relationship('Reviews', backref='pet') # reviewpcontact = db.relationship('Reviews', backref='petonwercontact') # reviewccontact = db.relationship('Reviews', backref='caretakercontact') # reviewstartdate = db.relationship('Reviews', backref='start') # reviewenddate = db.relationship('Reviews', backref='end') def get_status(self): return self.status def get_key(self): return (self.startdate, self.enddate, self.ccontact, self.petname, self.pcontact)
class UserRoles(db.Model): __tablename__ = 'user_roles' contact = db.Column(db.Integer, db.ForeignKey('users.contact', ondelete='CASCADE'), primary_key=True, nullable=False) usertype = db.Column(db.String, db.ForeignKey('role.name', ondelete='CASCADE'), nullable=False) userrolecontact = db.relationship('Users', foreign_keys=[contact]) userrolerole = db.relationship('Role', foreign_keys=[usertype])
class MoradorTable(db.Model): __tablename__ = 'morador' id = db.Column(db.Integer, primary_key=True) morador_idapt = db.Column(db.Integer, db.ForeignKey('apartamento.id'), nullable=False) morador_idprd = db.Column(db.Integer, db.ForeignKey('predio.id'), nullable=False) morador_idpes = db.Column(db.Integer, db.ForeignKey('pessoa.id'), unique=True, nullable=False) #Configuração dos relacionamentos evento_idmrd = db.relationship('EventoTable', backref='evento_idmorador', single_parent=True, cascade="all, delete-orphan") def __init__(self, morador_idapt, morador_idprd, morador_idpes): self.morador_idapt = morador_idapt self.morador_idprd = morador_idprd self.morador_idpes = morador_idpes
class Message(db.Model): id = db.Column(db.Integer, primary_key=True) to_user_id = db.Column(db.Integer, db.ForeignKey('user.id')) to_user = db.relationship('User', backref='incoming_messages', foreign_keys=[to_user_id]) from_user_id = db.Column(db.Integer, db.ForeignKey('user.id')) from_user = db.relationship('User', backref='messages', foreign_keys=[from_user_id]) conversation_id = db.Column(db.Integer, db.ForeignKey('conversation.id')) conversation = db.relationship('Conversation', backref='messages') txt = db.Column(db.String(1000)) created_at = db.Column(db.DateTime, default=datetime.now) status = db.Column(db.Integer, default=0) def __repr__(self): return self.txt @property def admin_url(self): return "%s/%s/%s" % (app.config['ADMIN_URL'], 'conversation', self.id) @property def url(self): return "%s/%s" % ('conversation', self.id)
class StuffPhoto(db.Model): id = db.Column(db.Integer, primary_key=True) filename = db.Column(db.String(255), nullable=False) owner_id = db.Column(db.Integer, db.ForeignKey('user.id')) owner = db.relationship('User', backref='object_photos') stuff_id = db.Column(db.Integer, db.ForeignKey('stuff.id')) stuff = db.relationship('Stuff', backref='photos')
class Cantakecare(db.Model, UserMixin): ccontact = db.Column(db.Integer, db.ForeignKey('users.contact', ondelete='CASCADE'), primary_key=True, nullable=False) category = db.Column(db.String, db.ForeignKey('categories.category', ondelete='CASCADE'), primary_key=True, nullable=False) def get_key(self): return (self.ccontact, self.category)
class Comment(db.Model): __tablename__ = 'comment' nid = db.Column(db.Integer, primary_key=True, autoincrement=True) # 评论者id user_info_id = db.Column(db.Integer, db.ForeignKey("userinfo.nid")) # 评论的信息id news_id = db.Column(db.Integer, db.ForeignKey("news.nid")) # 如果为None,就是评论文章,如果是数字就是回复某个人 reply_id = db.Column(db.Integer, db.ForeignKey("comment.nid"), nullable=True, default=None) # 顶一下 up = db.Column(db.Integer) # 踩一下 down = db.Column(db.Integer) # 创建时间 # ctime = db.Column(db.TIMESTAMP) ctime = db.Column(db.DateTime, nullable=False, default=datetime.utcnow, onupdate=datetime.utcnow) # 发表设备:手机,电脑,苹果.... device = db.Column(db.String(32)) # 发表内容 content = db.Column(db.String(150))
class notificationrules(db.Model): id = db.Column(db.Integer, primary_key=True) rule_template_id = db.Column( db.Integer, db.ForeignKey("notificationruletemplate.rule_template_id")) rule_uuid = db.Column(db.String(20)) notification_uuid = db.Column( db.String(20), db.ForeignKey("notificationheaders.notification_uuid")) arg1 = db.Column(db.String(20))
class ProjectJob(db.Model): __tablename__ = 'projects_jobs' project_id = db.Column(db.ForeignKey('projects.id'), primary_key=True) job_id = db.Column(db.ForeignKey('jobs.id'), primary_key=True) user_id = db.Column( db.Integer ) # "extra data" in association, a user_id associated with a ProjectJob
class PlaneDefensiveWeapon(db.Model): __tablename__ = "plane_defensive_weapons" id = db.Column(db.Integer, primary_key=True) quantity = db.Column(db.Integer) rounds = db.Column(db.Integer) weapon_id = db.Column(db.Integer, db.ForeignKey('weapons.weapon_id')) plane_id = db.Column(db.Integer, db.ForeignKey('planes.plane_id'))
class CorrectAnswers(db.Model): id = db.Column(db.Integer, primary_key=True) question_id = db.Column(db.Integer, db.ForeignKey('questions.id')) answer_id = db.Column(db.Integer, db.ForeignKey('answer_choices.id')) def __repr__(self): return "Id: {}, Question: {}, Answer: {}".format( self.id, self.question_id, self.answer_text)
class Cantakecare(db.Model, UserMixin): ccontact = db.Column(db.Integer, db.ForeignKey('users.contact'), primary_key=True, nullable=False) category = db.Column(db.String, db.ForeignKey('categories.category'), primary_key=True, nullable=False) dailyprice = db.Column(db.Integer, nullable=False) def get_dailyprice(self): return self.dailyprice def get_key(self): return (self.ccontact, self.category)
class GroupMembership(db.Model): __tablename__ = 'group_membership' user_id = db.Column(db.Integer, db.ForeignKey('user.id'), primary_key=True) group_id = db.Column(db.Integer, db.ForeignKey('group.id'), primary_key=True) is_moderator = db.Column(db.Boolean) user = db.relationship("User", backref='groups') def __repr__(self): return "%s[%s] " % (self.user.name, self.group.name)
class Answers(db.Model): id = db.Column(db.Integer, primary_key=True) answer = db.Column(db.String(120)) question_id = db.Column(db.Integer, db.ForeignKey('questions.id')) direction_id = db.Column(db.Integer, db.ForeignKey('directions.id')) def __init__(self, answer, question_id, direction_id): self.answer = answer self.question_id = question_id self.direction_id = direction_id
class Node(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) public_key = db.Column(db.String(512), unique=True) login_id = db.Column(db.Integer, db.ForeignKey('user.user_name_id')) computer_id = db.Column(db.Integer, db.ForeignKey('computer.computer_id')) ip = db.Column(db.String(15), unique=True, nullable=False) def __repr__(self): user = User.query.filter_by(user_name_id=self.login_id).first() return '<Node ' + user.user_name + '@' + self.ip + '>'
class Attempt(db.Model): __tablename__ = 'attempts' id = db.Column(db.Integer, primary_key=True) test_id = db.Column(db.Integer, db.ForeignKey('tests.id')) user_id = db.Column(db.Integer, db.ForeignKey('users.id')) score = db.Column(db.Integer) def __repr__(self): return "Id: {}, Test: {}, User: {}".format(self.id, self.test_id, self.user_id)
class ChosenAnswers(db.Model): id = db.Column(db.Integer, primary_key=True) attempt_id = db.Column(db.Integer, db.ForeignKey('attempts.id')) question_id = db.Column(db.Integer, db.ForeignKey('questions.id')) answer_id = db.Column(db.Integer, db.ForeignKey('answer_choices.id')) answer_text = db.Column(db.String) def __repr__(self): return "Id: {}, Question: {}, Attempt: {}, Answer: {}, Text: {}".format( self.id, self.question_id, self.attempt_id, self.answer_id, self.answer_text)
class Comment(db.Model): __tablename__ = 'comments' id = db.Column(db.Integer, primary_key=True) timestamp = db.Column(db.DateTime, index=True, default=datetime.now()) content = db.Column(db.Text) post_id = db.Column(db.Integer, db.ForeignKey('posts.id')) user_id = db.Column(db.Integer, db.ForeignKey('users.id')) def saveComment(self): db.session.add(self) db.session.commit()
class Bar(db.Model): BarID = db.Column(db.Integer, primary_key=True) Line = db.Column(db.String(128), index=True, unique=True) CorrectArtist = db.Column(db.Integer, db.ForeignKey('artist.ArtistID')) SongID = db.Column(db.Integer, db.ForeignKey('song.SongID')) def __repr__(self): return '<Bar {}'.format(self.BarID) def toJSON(self): return {'BarID': self.BarID, 'Line': self.Line}
class Questions(db.Model): id = db.Column(db.Integer, primary_key=True) question = db.Column(db.String(200)) direction_id = db.Column(db.Integer, db.ForeignKey('directions.id')) test_id = db.Column(db.Integer, db.ForeignKey('test.id')) answers = db.relationship('Answers', backref='questions', lazy='dynamic') is_control = db.Column(db.Boolean) def __init__(self, question, direction_id, test_id, is_control): self.question = question self.direction_id = direction_id self.test_id = test_id self.is_control = is_control
class team_game(db.Model): query_class = ArticleQuery team_name = db.Column(db.String(256), db.ForeignKey('team.name'), primary_key=True) game_id = db.Column(db.Integer, db.ForeignKey('game.id'), primary_key=True) # search_vector = db.Column(TSVectorType('game_id')) @property def serialize(self): return { "team_name" : self.team_name, "game_id" : self.game_id, }
class player_game(db.Model): query_class = ArticleQuery player_id = db.Column(db.Integer, db.ForeignKey('player.id'), primary_key=True) game_id = db.Column(db.Integer, db.ForeignKey('game.id'), primary_key=True) # search_vector = db.Column(TSVectorType('player_id', 'game_id')) @property def serialize(self): return { "player_id" : self.player_id, "game_id" : self.game_id, }
class Pets(db.Model, UserMixin): petname = db.Column(db.String, primary_key=True, nullable=False) pcontact = db.Column(db.Integer, db.ForeignKey('users.contact'), primary_key=True, nullable=False) category = db.Column(db.String, db.ForeignKey('categories.category'), nullable=False) age = db.Column(db.Integer, nullable=False) def is_active(self): return True def is_anonymous(self): return False def get_id(self): return (self.pcontact, self.petname)
class SaidaTable(db.Model): __tablename__ = 'saida' id = db.Column(db.Integer, primary_key=True) saida_idpes = db.Column(db.Integer, db.ForeignKey('pessoa.id'), nullable=False) saida_ident = db.Column(db.Integer, db.ForeignKey('entrada.id')) datahora = db.Column(db.DateTime, nullable=False) def __init__(self, saida_idpes, saida_ident, datahora): self.saida_idpes = saida_idpes self.saida_ident = saida_ident self.datahora = datahora
class Statistics(db.Model): __tablename__ = 'statistics' id = db.Column(db.Integer, primary_key=True) game_id = db.Column(db.Integer, db.ForeignKey('games.id')) team_id = db.Column(db.Integer, db.ForeignKey('teams.id')) name = db.Column(db.String) goals = db.Column(db.Integer) game = db.relationship('Game', back_populates='statistics') team = db.relationship('Team', back_populates='statistics') ball_possession=db.Column(db.Integer) distance_covered=db.Column(db.Integer) on_target=db.Column(db.Integer) pass_accuracy=db.Column(db.Integer)
class WareStorage(db.Model): ware_id = db.Column(db.Integer, db.ForeignKey('ware.id', onupdate='CASCADE'), primary_key=True) storage_id = db.Column(db.Integer, db.ForeignKey('storage.id', onupdate='CASCADE'), primary_key=True) ware_count = db.Column(db.INTEGER, default=1) wares = db.relationship("Ware", back_populates='st_ware') storages = db.relationship("Storage", back_populates='st_ware') def __repr__(self): return "Ware_id: {}, Storage_id: {}, Ware_count: {}".format( self.ware_id, self.storage_id, self.ware_count)
class Score(db.Model): __tablename__ = 'score' id = db.Column(db.Integer, primary_key=True) month = db.Column(db.Text) score = db.Column(db.Integer) badge = db.Column(db.Text) no_of_stars = db.Column(db.Text) empsc_id = db.Column(db.Integer, db.ForeignKey('employee.employee_id')) skillsc_id = db.Column(db.Integer, db.ForeignKey('skill.id')) def __init__(self, month, score, badge, no_of_stars): self.month = month self.score = score self.badge = badge self.no_of_stars = no_of_stars
class bookratings(db.Model): _tablename_ = "bookratings" id = db.Column(db.Integer) bookrating = db.Column(db.Integer, primary_key=True) userid = db.Column(db.Integer, db.ForeignKey("user.id")) isbn = db.Column(db.String(255), db.ForeignKey("book.isbn")) def __init__(self, id, bookrating, userid, isbn): self.id = id self.bookrating = bookrating self.userid = userid self.isbn = isbn def __repr__(self): return '<id %r>' % self.id