class Show(db.Model): __tablename__ = 'Show' venue_id = db.Column(db.Integer, db.ForeignKey('Venue.id'), primary_key=True) artist_id = db.Column(db.Integer, db.ForeignKey('Artist.id'), primary_key=True) starttime = db.Column(db.DateTime, primary_key=True) artist = db.relationship('Artist', lazy='joined') @property def info(self): return { 'venue_id': self.venue.id, 'venue_name': self.venue.name, 'artist_id': self.artist.id, 'artist_name': self.artist.name, 'artist_image_link': self.artist.image_link, 'start_time': self.starttime.isoformat() + 'Z' } def __init__(self, venue=None, artist=None, starttime=None): self.venue = venue self.artist = artist self.starttime = starttime def __repr__(self): return f'<{self.artist.name} @ {self.venue.name}: {self.starttime}>'
class LikePost(db.Model): __tablename__ = 'likepost' id = db.Column(db.Integer, primary_key=True, autoincrement=True) user_id = db.Column(db.Integer, db.ForeignKey('users.id')) recipe_id = db.Column(db.Integer, db.ForeignKey('recipe.id')) def __repr__(self): return '<Like id %r>' % self.id
class Author(db.Model): __tablename__ = 'authors' id_presentation = db.Column(db.Integer, db.ForeignKey('presentations.id'), primary_key=True) id_user = db.Column(db.Integer, db.ForeignKey('users.id'), primary_key=True)
class Group(db.Model): """Create a test table.""" __tablename__ = 'group' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(60), index=True) spec_id = db.Column(db.Integer, db.ForeignKey('specification.id')) test_id = db.Column(db.Integer, db.ForeignKey('test.id'))
class UserRoles(db.Model): __tablename__ = "user_roles" id = db.Column(db.Integer(), primary_key=True) user_id = db.Column(db.Integer(), db.ForeignKey("users.id", ondelete="CASCADE")) role_id = db.Column(db.Integer(), db.ForeignKey("roles.id", ondelete="CASCADE"))
class Order(Model): __tablename__ = 'order' order_id = db.Column(db.Integer, primary_key=True, autoincrement=True) buyer_id = db.Column(db.Integer, db.ForeignKey('buyer.buyer_id'), nullable=True) buyer = db.relationship('Buyer', backref=db.backref('orders', lazy=True)) supplier_id = db.Column(db.Integer, db.ForeignKey('supplier.supplier_id'), nullable=True) supplier = db.relationship('Supplier', backref=db.backref('orders', lazy=True)) date_created = db.Column(db.Date) time_created = db.Column(db.Time) accepted = db.Column(db.Boolean) status = db.Column(db.String(45)) price = db.Column(db.Float) rate = db.Column(db.Integer) comment = db.Column(db.String(255)) ship_price_buyer = db.Column(db.Float) ship_price_supplier = db.Column(db.Float) ship_price = db.Column(db.Float) def __init__(self, buyer_id=None, supplier_id=None, date_created=None, time_created=None, accepted=None, status=None, price=None, rate=None, comment=None, ship_price_buyer=None, ship_price_supplier=None, ship_price=None): self.buyer_id = buyer_id self.supplier_id = supplier_id self.date_created = date_created self.time_created = time_created self.accepted = accepted self.status = status self.price = price self.rate = rate self.comment = comment self.ship_price_buyer = ship_price_buyer self.ship_price_supplier = ship_price_supplier self.ship_price = ship_price
class Image(Model): __tablename__ = 'images' Name = db.Column(db.String(31), unique=True) URL = db.Column(db.Text) Sol = db.Column(db.Integer, nullable=False) DetatchedLabel = db.Column(db.Boolean) CameraID = db.Column( db.Integer, db.ForeignKey('cameras.ID'), nullable=False, ) ProductTypeID = db.Column( db.Integer, db.ForeignKey('product_types.ID'), nullable=False, ) @classmethod def from_dict(cls, image_dict: Dict[str, Any]) -> 'Image': return cls( Name=str(image_dict['Name']), URL=str(image_dict['URL']), Sol=int(image_dict['Sol']), DetatchedLabel=bool(image_dict['DetatchedLabel']), CameraID=int(image_dict['CameraID']), ProductTypeID=int(image_dict['ProductTypeID']), ) def to_dict(self) -> Dict[str, Any]: to_dict = super().to_dict() to_dict.update({ 'Name': self.Name, 'URL': self.URL, 'Sol': self.Sol, 'DetatchedLabel': self.DetatchedLabel, 'CameraID': self.CameraID, 'camera': self.camera.to_dict(), 'ProductTypeID': self.ProductTypeID, 'product_type': self.product_type.to_dict(), }) return to_dict def update_from_dict(self, image_dict: Dict[str, Any]) -> None: super().update_from_dict(image_dict) if 'Name' in image_dict: self.Name = image_dict['Name'] if 'URL' in image_dict: self.URL = image_dict['URL'] if 'Sol' in image_dict: self.Sol = image_dict['Sol'] if 'DetatchedLabel' in image_dict: self.DetatchedLabel = image_dict['DetatchedLabel'] if 'CameraID' in image_dict: self.CameraID = image_dict['CameraID'] if 'ProductTypeID' in image_dict: self.ProductTypeID = image_dict['ProductTypeID']
class Comment(Model): __tablename__ = "COMMENT" commentID = db.Column(db.Integer, primary_key=True, autoincrement=True) content = db.Column(db.String(1000), nullable=False) rate = db.Column(db.Integer, nullable=False) ordererID = db.Column(db.Integer, db.ForeignKey('USER.userID')) shipperID = db.Column(db.Integer, db.ForeignKey('USER.userID')) time = db.Column(db.DateTime, nullable=False)
class JobSkill(db.Model): __tablename__ = 'jobs_skills' job_uuid = db.Column(db.String, db.ForeignKey('jobs_master.uuid'), primary_key=True) skill_uuid = db.Column(db.String, db.ForeignKey('skills_master.uuid'), primary_key=True) def __init__(self, job_uuid, skill_uuid): self.job_uuid = job_uuid self.skill_uuid = skill_uuid def __repr__(self): return '<uuid {}>'.format(self.job_uuid)
class JobImportance(db.Model): __tablename__ = 'jobs_importance' quarter_id = db.Column(db.SmallInteger, db.ForeignKey('quarters.quarter_id'), primary_key=True) geography_id = db.Column(db.SmallInteger, db.ForeignKey('geographies.geography_id'), primary_key=True) job_uuid = db.Column(db.String, primary_key=True) importance = db.Column(db.Float) def __repr__(self): return '<JobImportance {}/{}/{}>'.format( self.geography_id, self.quarter_id, self.job_uuid )
class Hint(db.Model): __tablename__ = 'hint' id = db.Column(db.Integer, primary_key=True) order = db.Column(db.Integer, nullable=False) content = db.Column(db.UnicodeText, nullable=False) question_id = db.Column(db.Integer, db.ForeignKey('question.id')) def __serialize__(self): return { 'id': self.id, 'order': self.order, 'content': self.content, 'questionId': self.question_id } def set_question(self, question_id): question = Question.query.filter(Question.id == question_id).first() if not question: return not_found('Question with id ' + question_id + ' not found.') self.question = question def update(self, **args): if 'id' in args: raise TypeError('Cannot update id.') if 'content' in args: self.content = args['content'] if 'order' in args: self.order = args['order'] if 'questionId' in args: self.set_question(args['questionId']) return self
class Driver(db.Model): id = db.Column(db.Integer, primary_key=True) first_name = db.Column(db.String(255), nullable=False) last_name = db.Column(db.String(255), nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) user = db.relationship("User", back_populates="driver") trips = db.relationship("Trip", backref="driver", lazy=True)
class Sale(db.Model): __tablename__ = 'sales' id_product = db.Column(db.Integer, db.ForeignKey('products.id'), nullable=False, primary_key=True) date_sale = db.Column(db.DateTime, nullable=False) amount = db.Column(db.Integer, nullable=False) def __init__(self, **kwargs): super().__init(**kwargs) self.init_load() @reconstructor def init_load(self): self.id_product = self.id_product self.date_sale = self.encrypt(self.date_sale) self.amount = self.encrypt(self.amount) def encrypt(self, value): key = b'1234567890123456' value = bytes(str(value), 'utf-8') return aes.encrypt(key, value) def decrypt(self, value): key = b'1234567890123456' return aes.decrypt(key, value)
class Trip(db.Model): id = db.Column(db.Integer, primary_key=True) start_location = db.Column(db.String(255), nullable=False) end_location = db.Column(db.String(255), nullable=False) departure_date = db.Column(db.DateTime(timezone=True), nullable=False) return_date = db.Column(db.DateTime(timezone=True), nullable=False) available_seats = db.Column(db.Integer, nullable=False) driver_id = db.Column(db.Integer, db.ForeignKey('driver.id'), nullable=False) riders = db.relationship('Rider', secondary=trip_riders, lazy='subquery', back_populates='trips') def remove_rider_from_trip(self, rider_id): new_riders = [rider for rider in self.riders if rider.id != rider_id] self.riders = new_riders self.available_seats = self.available_seats + 1 db.session.commit() def add_rider_to_trip(self, rider_id): self.riders.append(rider_id) self.available_seats = self.available_seats - 1 db.session.commit()
class ItemModel(db.Model): __tablename__ = 'items' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(80)) price = db.Column(db.Float(precision=2)) store_id = db.Column(db.Integer, db.ForeignKey('stores.id')) store = db.relationship('StoreModel') def __init__(self, name, price, store_id): self.name = name self.price = price self.store_id = store_id def json(self): return {'name': self.name, 'price': self.price} @classmethod def find_by_name(cls, name): return cls.query.filter_by(name=name).first() def save_to_db(self): db.session.add(self) db.session.commit() def delete_from_db(self): db.session.delete(self) db.session.commit()
class Key(db.Model): __tablename__ = 'keys' id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) key_value = db.Column(db.String(50)) key_type = db.Column(db.String(25))
class History(Model): __tablename__ = "history" history_id = db.Column(db.Integer, primary_key=True, autoincrement=True) user_id = db.Column(db.Integer, db.ForeignKey('user.user_id'), nullable=False) user = db.relationship('User', backref=db.backref('histories', lazy=True)) description = db.Column(db.String, nullable=False) date_created = db.Column(db.Date, nullable=False) time_created = db.Column(db.Time, nullable=False) def __init__(self, user_id, description, date_created=None, time_created=None): self.user_id = user_id self.description = description if date_created is None: date_created = datetime.datetime.today().date() if time_created is None: time_created = datetime.datetime.now().time() self.date_created = date_created self.time_created = time_created
class Pet(db.Model): """Modelo Mascota Pet(id_pet, name_pet, type_pet, age_pet, name_profile_img) Nota: al registrar una mascota, el valor de adopcion siempre sera False Relaciones: - Mascota tendrá la llave primaria de Persona """ id_pet = db.Column(db.Integer, primary_key = True) name_pet = db.Column(db.String(25), nullable = False) type_pet = db.Column(db.String(25), nullable = False) age_pet = db.Column(db.Integer(), nullable = False) adopt = db.Column(db.Boolean(), nullable = False, default = False) name_profile_img = db.Column(db.String, default = 'default.jpg' , nullable = True) url_profile_img = db.Column(db.String, default = 'http://localhost:5000/static/profile_img/default.jpg' , nullable = True) # Referencia a la clase Persona id_owner = db.Column(db.Integer, db.ForeignKey('person.id_person'), nullable = True) def __repr__(self): return self.name_pet
class GeoTitleCount(db.Model): __tablename__ = 'geo_title_counts' quarter_id = db.Column(db.SmallInteger, db.ForeignKey('quarters.quarter_id'), primary_key=True) geography_id = db.Column(db.SmallInteger, db.ForeignKey('geographies.geography_id'), primary_key=True) job_uuid = db.Column(db.String, primary_key=True) job_title = db.Column(db.String) count = db.Column(db.Integer) def __repr__(self): return '<GeoTitleCount {}/{}/{}: {}>'.format(self.geography_id, self.quarter_id, self.job_uuid, self.count)
class CollateDataSave(db.Model): id = db.Column(db.Integer, primary_key=True) project_id = db.Column(db.Integer, db.ForeignKey("project.id"), index=True) save_name = db.Column(db.String(50), index=False) condition = db.Column(db.String(50), index=False) condition_col = db.Column(db.String(50), index=False) action = db.Column(db.String(50), index=False) action_col = db.Column(db.String(50), index=False)
class Schedule(db.Model): __tablename__ = 'schedule' id = db.Column(db.Integer, nullable=False, primary_key=True) date_start = db.Column(db.DateTime, nullable=False) id_presentation = db.Column(db.Integer, db.ForeignKey('presentations.id'), nullable=False) id_room = db.Column(db.Integer, db.ForeignKey('rooms.id'), nullable=False) def is_room_busy(self, date_start, id_room): sched = Schedule.query.filter_by(id_room=int(id_room), date_start=datetime.strptime( date_start, '%Y-%m-%d %H:%M:%S')).first() if sched is None: return False return True
class ArtistGenres(db.Model): __tablename__ = 'ArtistGenres' artist_id = db.Column(db.Integer, db.ForeignKey('Artist.id'), primary_key=True) genre = db.Column(GenreEnum_, primary_key=True) def __repr__(self): return f'{self.genre}'
class Warehouse(db.Model): __tablename__ = 'warehouse' id_product = db.Column(db.Integer, db.ForeignKey('products.id'), nullable=False, primary_key=True) date_of_delivery = db.Column(db.Date, nullable=False) amount = db.Column(db.Integer, nullable=False) retail_price = db.Column(db.Integer, nullable=False)
class VenueGenres(db.Model): __tablename__ = 'VenueGenres' venue_id = db.Column(db.Integer, db.ForeignKey('Venue.id'), primary_key=True) genre = db.Column(GenreEnum_, primary_key=True) def __repr__(self): return f'{self.genre}'
class Result(db.Model): """Create a user table.""" __tablename__ = 'result' id = db.Column(db.Integer, primary_key=True) status = db.Column(db.String(60)) timestamp = db.Column(db.DateTime()) spec_name = db.Column(db.String(60)) time = db.Column(db.Integer) test_id = db.Column(db.Integer, db.ForeignKey('test.id'))
class PodcastEpisodeModel(BaseModel, db.Model): __tablename__ = 'podcast_episode' episode_id = db.Column(db.Text, primary_key=True) episode_number = db.Column(db.Integer) title = db.Column(db.Text) description = db.Column(db.Text) uri = db.Column(db.Text) published_date = db.Column(db.DateTime) show_id = db.Column(db.Text, db.ForeignKey('podcast_show.show_id'), nullable=False)
class Column(db.Model): id = db.Column(db.Integer, primary_key=True) project_id = db.Column(db.Integer, db.ForeignKey("project.id"), index=True) position = db.Column(db.Integer) name = db.Column(db.String(50)) d_type = db.Column(db.String(20)) format = db.Column(db.String(50), nullable=True) def __repr__(self): return "<Column project_id={} position={}>".format( self.project_id, self.position)
class Product(db.Model): __tablename__ = 'products' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100), nullable=False) shelf_life = db.Column(db.Date, nullable=False) trade_price = db.Column(db.Integer, nullable=False) id_unit = db.Column(db.Integer, db.ForeignKey('units.id'), nullable=False) id_category = db.Column(db.Integer, db.ForeignKey('categories.id'), nullable=False) id_supplier = db.Column(db.Integer, db.ForeignKey('suppliers.id'), nullable=False) sale = db.relationship('Sale', backref='products') warehouse = db.relationship('Warehouse', backref='products') def __str__(self): return self.name
class Employee(db.Model): """Model for an employee.""" id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(50), nullable=False) date_of_birth = db.Column(db.DateTime, nullable=False) salary = db.Column(db.Float, nullable=False) department_id = db.Column(db.Integer, db.ForeignKey("department.id"), nullable=False) department = db.relationship("Department", backref="department", lazy=True) def __repr__(self): return f"""
class Answer(db.Model): __tablename__ = 'answer' id = db.Column(db.Integer, primary_key=True) content = db.Column(db.UnicodeText, nullable=False) question_id = db.Column(db.Integer, db.ForeignKey('question.id')) def __serialize__(self): return { 'id': self.id, 'content': self.content, 'question': self.question_id }