class Tweet(db.Model): __tablename__ = "tweets" id = db.Column(db.Integer, primary_key=True, autoincrement=True) content = db.Column(db.String(140), nullable=False) created_date = db.Column(db.DateTime, default=func.now()) user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
class Post(db.Model): id = db.Column(db.Integer, primary_key=True) body = db.Column(db.String(140)) timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow) user_id = db.Column(db.Integer, db.ForeignKey('users.id')) def __repr__(self): return '<Post {}>'.format(self.body)
class Post(db.Model): id = db.Column(db.Integer, primary_key=True) body = db.Column(db.String(140)) timestamp = db.Column(db.DateTime) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) def __repr__(self): return '<Post %r>' % (self.body)
class IrrigationSchedules(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) start_time = db.Column(db.DateTime, nullable=False) machine_id = db.Column(db.Integer, db.ForeignKey('machines.id')) machine = db.relationship("Machines", back_populates="irrigation_schedules")
class Patent(db.Model): __tablename__ = "patent" id = db.Column(db.Integer, primary_key=True) human_id = db.Column(db.Integer, db.ForeignKey('human.id'), nullable=False) title = db.Column(db.String(200), nullable=False) description = db.Column(db.String(250), nullable=False) patent_number = db.Column(db.String(20), nullable=False) inventors = db.Column(db.String(250), nullable=False) issue_date = db.Column(db.DateTime, nullable=True) patent_office_id = db.Column(db.Integer, db.ForeignKey('patent_office.id')) patent_office = db.relationship('PatentOffice', backref=db.backref('patent', lazy='dynamic')) patent_status_id = db.Column(db.Integer, db.ForeignKey('patent_status.id')) patent_status = db.relationship('PatentStatus', backref=db.backref('patent', lazy='dynamic')) patent_url = db.Column(db.String(100), nullable=True) def __repr__(self): return self.status
class Folder(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(100), nullable=False) date_created = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) location = db.Column(db.String(200), nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
class Device(db.Model): __tablename__ = "devices" id = db.Column(db.Integer, primary_key=True, autoincrement=True) device_id = db.Column(db.String(128), unique=True, nullable=False) device_type = db.Column(db.String(128), nullable=False) active = db.Column(db.Boolean, default=True, nullable=False) pn_token = db.Column(db.String(256), unique=True) user_id = db.Column(db.Integer, db.ForeignKey('users.id')) user = db.relationship('User', backref=db.backref('devices', lazy='joined')) created_at = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) updated_at = db.Column(db.DateTime, nullable=False, default=datetime.utcnow, onupdate=datetime.utcnow) def __init__(self, device_id: str, device_type: str, pn_token: str=None, active: bool=True, user=None, created_at: datetime=datetime.utcnow()): self.device_id = device_id self.device_type = device_type # "apple" "android" self.pn_token = pn_token self.active = active self.user = user self.created_at = created_at self.updated_at = created_at # noinspection PyPep8 @staticmethod def query_active_devices_for_user(user: User): return Device.query.filter(Device.user_id == user.id, Device.active == True, Device.pn_token.isnot(None)) # noinspection PyPep8 @staticmethod def query_active_devices_for_group(group: Group, discard_user_ids:List[int]=None): discard_user_ids = discard_user_ids or [] user_ids = [user.user_id for user in group.associated_users if user.user_id not in discard_user_ids] return Device.query.filter(Device.user_id.in_(tuple(user_ids)), Device.active == True, Device.pn_token.isnot(None)) @staticmethod def create_or_update(device_id, device_type: str, user:User=None, active: bool = True, pn_token: str=None): device = Device.first_by(device_id=device_id) if not device: device = Device(device_id=device_id, device_type=device_type, user=user, active=active, pn_token=pn_token) db.session.add(device) else: device.device_type = device_type device.active = active if user: device.user = user if pn_token: device.pn_token = pn_token return device @staticmethod def first_by(**kwargs): """Get first db device that match to device_id""" return Device.query.filter_by(**kwargs).first() @staticmethod def first(*criterion): """Get first db entity that match to criterium""" return Device.query.filter(*criterion)
class Bid(db.Model): __tablename__ = "bid" id = db.Column(db.Integer, primary_key=True) description = db.Column(db.String) notes = db.Column(db.String) timestamp = db.Column(db.DateTime) customer_id = db.Column(db.Integer, db.ForeignKey('customer.id')) address_id = db.Column(db.Integer, db.ForeignKey('address.id')) scheduled_bid_date = db.Column(db.DateTime) tentative_start = db.Column(db.Date) actual_start = db.Column(db.Date) completion_date = db.Column(db.Date) down_payment_amount = db.Column(db.Float, default=0) down_payment_date = db.Column(db.Date) final_payment_amount = db.Column(db.Float, default=0) final_payment_date = db.Column(db.Date) status = db.Column(db.String) bid_items = db.relationship('BidItem', backref='bid_item', cascade="all, delete-orphan", lazy='joined') def __init__(self, description, notes, timestamp, customer_id, address_id, scheduled_bid_date, tentative_start, actual_start, completion_date, down_payment_amount, down_payment_date, final_payment_amount, final_payment_date, status): self.description = description self.notes = notes self.timestamp = timestamp self.customer_id = customer_id self.address_id = address_id self.scheduled_bid_date = scheduled_bid_date self.tentative_start = tentative_start self.actual_start = actual_start self.completion_date = completion_date self.down_payment_amount = down_payment_amount self.down_payment_date = down_payment_date self.final_payment_amount = final_payment_amount self.final_payment_date = final_payment_date self.status = status def __repr__(self): return '<{}>'.format(self.description)
class Line(db.Model): _N = 3 __tablename__ = "lines" id = db.Column(db.Integer, primary_key=True, autoincrement=True) container = db.Column(db.String(32), index=True) dimensions = db.Column(db.String(32), index=True) substrate = db.Column(db.String(64), index=True) treatment = db.Column(db.String(64), index=True) timestamp = db.Column( db.DateTime(), default=datetime.datetime.utcnow, index=True ) path = db.Column(db.Text, index=True) parent_id = db.Column(db.Integer, db.ForeignKey('lines.id')) active = db.Column(db.Boolean, default=True) contam = db.Column(db.Boolean, default=False) user_id = db.Column( db.Integer, db.ForeignKey('users.id'), nullable=False ) culture_id = db.Column( db.String(32), db.ForeignKey('cultures.culture_id'), nullable=False ) expansions = db.relationship( 'Line', backref=db.backref('parent', remote_side=[id]), lazy='dynamic' ) def __repr__(self): return '<Line %r>' % (self.id) def save(self): db.session.add(self) db.session.commit() prefix = self.parent.path + '.' if self.parent else '' self.path = prefix + '{:0{}d}'.format(self.id, self._N) db.session.commit() def level(self): return len(self.path) # self._n - 1
class UserVO(db.Model): __tablename__ = 'usermaster' userId = db.Column('userId', db.Integer, primary_key=True, autoincrement=True) userFirstName = db.Column('userFirstName', db.String(100), nullable=False) userLastName = db.Column('userLastName', db.String(100), nullable=False) userBirthDate = db.Column('userBirthDate', db.String(100), nullable=False) user_BloodGroupId = db.Column('user_BloodGroupId', db.Integer, db.ForeignKey(BloodGroupVO.bloodGroupId)) userGender = db.Column('userGender', db.String(100), nullable=False) userWeight = db.Column('userWeight', db.String(100), nullable=False) userHeight = db.Column('userHeight', db.String(100), nullable=False) userContact = db.Column('userContact', db.String(100), nullable=False) userFileName = db.Column('userFileName', db.String(100), nullable=False) userFilePath = db.Column('userFilePath', db.String(100), nullable=False) user_CityId = db.Column('user_CityId', db.Integer, db.ForeignKey(CityVO.cityId)) user_AreaId = db.Column('user_AreaId', db.Integer, db.ForeignKey(AreaVO.areaId)) userAddress = db.Column('userAddress', db.String(100), nullable=False) userDiseases = db.Column('userDiseases', db.String(100), nullable=False) user_LoginId = db.Column('user_LoginId', db.Integer, db.ForeignKey(LoginVO.loginId)) def as_dict(self): return { 'userId': self.userId, 'userFirstName': self.userFirstName, 'userLastName': self.userLastName, 'userName': self.userName, 'userBloodGroup': self.userBloodGroup, 'userGender': self.userGender, 'userWeight': self.userWeight, 'userHeight': self.userHeight, 'userContact': self.userContact, 'userFileName': self.userFileName, 'userFilePath': self.userFilePath, 'user_CityId': self.user_CityId, 'user_AreaId': self.user_AreaId, 'userAddress': self.userAddress, 'userDiseases': self.userDiseases, 'user_LoginId': self.user_LoginId }
class Freewrite(db.Model): __tablename__ = 'freewrite' id = db.Column(db.Integer, primary_key=True) content = db.Column(db.Text, nullable=False) question = db.Column(db.Text, nullable=False) complete = db.Column(db.Boolean, nullable=False, default=False) received_feedback = db.Column(db.Boolean, nullable=False, default=False) searching_feedback = db.Column(db.Boolean, nullable=False, default=True) prompt_id = db.Column(db.Integer, db.ForeignKey('prompt.id'), nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) feedback = db.relationship('Feedback', backref='freewrite', lazy=True) def __repr__(self): return f"Freewrite('{self.id}')"
class GitHubContributions(db.Model, AddUpdateDelete): __tablename__ = 'githubcontributions' id = db.Column(db.Integer, primary_key=True) swag_id = db.Column(db.Integer, db.ForeignKey('swag.id')) time_logged = db.Column(db.DateTime(timezone=True), unique=False) github_url = db.Column(db.Text, unique=False) point_value = db.Column(db.Integer) swag = db.relationship("Swag")
class CarClass(db.Model): __tablename__ = 'car_classes' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String, nullable=False) game_id = db.Column(db.Integer, db.ForeignKey('games.id')) # Foreign keys cars = db.relationship('Car', backref='car_class', lazy='dynamic')
class Music(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(120)) person_id = db.Column(db.Integer, db.ForeignKey("person.id"), nullable=False) person = db.relationship("Person", backref="musics") def __init__(self, title, person_id): self.title = title self.person_id = person_id
class Outfit(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(30), index=True, nullable=True) note = db.Column(db.String(140), nullable=True) owner_id = db.Column(db.Integer, db.ForeignKey("user.id")) timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow) outerwear_id = db.Column(db.Integer, db.ForeignKey("clothes.id")) top_1_id = db.Column(db.Integer, db.ForeignKey("clothes.id")) top_2_id = db.Column(db.Integer, db.ForeignKey("clothes.id")) bottom_id = db.Column(db.Integer, db.ForeignKey("clothes.id")) outerwear = db.relationship("Clothes", foreign_keys="Outfit.outerwear_id") top_1 = db.relationship("Clothes", foreign_keys="Outfit.top_1_id") top_2 = db.relationship("Clothes", foreign_keys="Outfit.top_2_id") bottom = db.relationship("Clothes", foreign_keys="Outfit.bottom_id") def __repr__(self): return f"<Outfit {self.name}>"
class Opportunity(Post): __tablename__ = 'opportunities' id = db.Column(db.Integer, db.ForeignKey('posts.id'), primary_key=True) __mapper_args__ = { 'polymorphic_identity': 'opportunity' }
class Preference(db.Model): __tablename__ = 'Preference' id = db.Column(db.Integer, primary_key=True) preference = db.Column(db.String(128), nullable=False) listing_id = db.Column(db.Integer, db.ForeignKey('Listing.id'), nullable=False)
class Passenger(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(32)) addr = db.Column(db.String(64)) phone = db.Column(db.String(16)) ride_id = db.Column(db.Integer, db.ForeignKey('ride.id')) def __repr__(self): return '<Passenger> {} {}'.format(self.name, self.ride_id)
class BabyMonitorReceive(db.Model): """ type: confirmation / ??? """ __tablename__ = "baby_monitor_receive" id = db.Column(db.Integer, unique=True, nullable=False, primary_key=True) type = db.Column(db.String(80), nullable=True, default='confirmation') time = db.Column(db.DateTime, nullable=False) id_notification = db.Column(db.Integer, db.ForeignKey("baby_monitor_send.id"))
class Notification(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(128), index=True) user_id = db.Column(db.Integer, db.ForeignKey("user.id")) timestamp = db.Column(db.Float, index=True, default=time) payload_json = db.Column(db.Text) def get_data(self): return json.loads(str(self.payload_json))
class BlogPost(db.Model): id = db.Column(db.Integer()) user_id = db.Column(db.ForeignKey("users.id"), nullable=False) title = db.Column(db.String(140), nullable=False) pub_date = db.Column(db.DATETIME(), default=datetime.utcnow , nullable=False) text = db.Column(db.TEXT(), nullable=False) def __repr__(self): return f"Post {self.title} "
class Material(db.Model): # Used for all products __tablename__ = 'materials' id = db.Column(db.Integer, primary_key=True) product_id = db.Column(db.Integer, db.ForeignKey('products.id'), nullable=False) material_name = db.Column(db.String(100), nullable=False) quantity = db.Column(db.Float, nullable=False) units = db.Column(db.String(100), nullable=False) def __repr__(self): return '<Food %r>' % (self.material_name)
class UserAuctionParticipation(db.Model): __tablename__ = 'user_auction_participations' id = db.Column(db.BigInteger, primary_key=True) auction_id = db.Column(db.BigInteger, db.ForeignKey('auctions.id')) auction = db.relationship('Auction') user_id = db.Column(db.BigInteger, db.ForeignKey('users.id')) user = db.relationship('User') created = db.Column(db.TIMESTAMP, default=datetime.datetime.now, nullable=False) updated = db.Column(db.TIMESTAMP, default=datetime.datetime.now, nullable=False, onupdate=datetime.datetime.now)
class IrrigationsHistory(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) irrigation_date = db.Column(db.DateTime, nullable=False) irrigation_mode = db.Column(db.Integer, nullable=False) planting_id = db.Column(db.Integer, db.ForeignKey('plantings.id')) planting = db.relationship("Plantings", back_populates="irrigations_history")
class ListingImage(db.Model): __tablename__ = 'ListingImage' id = db.Column(db.Integer, primary_key=True) url = db.Column(db.Text, nullable=False) listing_id = db.Column(db.Integer, db.ForeignKey('Listing.id'), nullable=False)
class Publication(db.Model): __tablename__ = "publication" id = db.Column(db.Integer, primary_key=True) human_id = db.Column(db.Integer, db.ForeignKey('human.id'), nullable=False) title = db.Column(db.String(100), nullable=False) authors = db.Column(db.String(250), nullable=True) publication_date = db.Column(db.DateTime, nullable=True) publisher = db.Column(db.String(250), nullable=True) publication_url = db.Column(db.String(100), nullable=True) description = db.Column(db.String(250), nullable=True) publication_category_id = db.Column(db.Integer, db.ForeignKey('publication_category.id')) publication_category = db.relationship('PublicationCategory', backref=db.backref('publication', lazy='dynamic')) def __repr__(self): return self.id
class Idea(Post): __tablename__ = 'ideas' id = db.Column(db.Integer, db.ForeignKey('posts.id'), primary_key=True) __mapper_args__ = { 'polymorphic_identity': 'idea' }
class Owner(db.Model): __tablename__ = 'owners' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.Text) ponny_id = db.Column(db.Integer, db.ForeignKey('ponnies.id')) def __init__(self, name, ponny_id): self.name = name self.ponny_id = ponny_id
class Education(db.Model): __tablename__ = "education" id = db.Column(db.Integer, primary_key=True) human_id = db.Column(db.Integer, db.ForeignKey('human.id'), nullable=False) educational_institution = db.Column(db.String(200), nullable=False) educational_institution_type_id = db.Column(db.Integer, nullable=True) course_studied = db.Column(db.String(200), nullable=True) start_date = db.Column(db.DateTime, nullable=True) end_date = db.Column(db.DateTime, nullable=True) accolades = db.Column(db.String(400), nullable=True) educational_institution_type_id = db.Column(db.Integer, db.ForeignKey('educational_institution_type.id')) educational_institution_type = db.relationship('EducationalInstitutionType', backref=db.backref('education', lazy='dynamic')) def __repr__(self): return '<id: {}'.format(self.id)
class Comment(db.Model): __table_args__ = {'mysql_collate': 'utf8_general_ci'} id = db.Column(db.Integer, primary_key=True, autoincrement=True) content = db.Column(db.String(1024)) image_id = db.Column(db.Integer, db.ForeignKey('image.id')) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) created_date = db.Column(db.DateTime) status = db.Column(db.Integer, default=0) # 0 正常 1删除 user = db.relationship('User') def __init__(self, content, image_id, user_id): self.content = content self.image_id = image_id self.user_id = user_id self.created_date = datetime.now() def __repr__(self): return ('<Comment%d %s>' % (self.id, self.content)).encode('gbk')