class Stock(db.Model): __tablename__ = "stocks" ticker = db.Column(db.String(32), primary_key=True) name = db.Column(db.String(128), nullable=False) sticker = db.Column(db.Float, nullable=True) margin = db.Column(db.Float, nullable=True) avg_eps_growth = db.Column(db.Float, nullable=True) qoq_eps_growth = db.Column(db.Float, nullable=True) avg_sales_growth = db.Column(db.Float, nullable=True) qoq_sales_growth = db.Column(db.Float, nullable=True) sales = db.relationship('Revenues', backref='stock', lazy=True) epss = db.relationship('EPS', backref='stock', lazy=True) equity = db.relationship('Equity', backref='stock', lazy=True) freecash = db.relationship('FreeCash', backref='stock', lazy=True) def __init__(self, name, ticker, sticker=None, margin=None): self.name = name self.ticker = ticker.upper() self.sticker = sticker self.margin = margin def to_json(self): return { 'name': self.name, 'ticker': self.ticker, 'sticker': self.sticker, 'margin': self.margin, 'avgEpsGrowth': self.avg_eps_growth, 'qoqEpsGrowth': self.qoq_eps_growth, 'avgSalesGrowth': self.avg_sales_growth, 'qoqSalesGrowth': self.qoq_sales_growth }
class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20), unique=True, nullable=False) email = db.Column(db.String(120), unique=True, nullable=False) image_file = db.Column(db.String(20), nullable=False, default='default.jpg') password = db.Column(db.String(60), nullable=False) courses = db.relationship('Course', backref='author', lazy=True) teachers = db.relationship('Teacher', backref='author', lazy=True) classes = db.relationship('Clas', backref='author', lazy=True) def get_reset_token(self, expires_sec=1800): s = Serializer(current_app.config['SECRET_KEY'], expires_sec) return s.dumps({'user_id': self.id}).decode('utf-8') @staticmethod def verify_reset_token(token): s = Serializer(current_app.config['SECRET_KEY']) try: user_id = s.loads(token)['user_id'] except: return None return User.query.get(user_id) def __repr__(self): return f"User('{self.username}', '{self.email}', '{self.image_file}')"
class Incident(db.Model): __tablename__ = 'incident' # Attributes incidentID = db.Column(db.Integer, primary_key=True, autoincrement=True) postalCode = db.Column(db.String(10), unique=False, nullable=False) address = db.Column(db.String(200), unique=False, nullable=False) description = db.Column(db.String(200), nullable=True) #Will be computed based by address entered longtitude = db.Column(db.String(120), unique=False, nullable=False) latitude = db.Column(db.String(120), unique=False, nullable=False) gpid = db.Column(db.Integer, db.ForeignKey('general_public.gpid')) operatorID = db.Column(db.Integer, db.ForeignKey('operator.operatorid')) timeStamp=db.Column(db.DateTime, nullable=False, default=sgtimestampnow) # Relationships # Association of proxy incident_assigned_to_relevant_agencies to releevant_agencies emergencyType = db.relationship("EmergencyType", secondary=incident_has_emergencyType, backref="incidents") assistanceType = db.relationship("AssistanceType", secondary=incident_request_assistanceType, backref="incidents") relevantAgencies = association_proxy('incident_assigned_to_relevant_agencies', 'relevantAgency',creator=lambda relevantAgency: IncidentAssignedToRelevantAgencies(relevantAgency=relevantAgency)) operator = relationship("Operator", backref="incidents") reportedUser = relationship("GeneralPublic", backref="reportedIncident") # To access list of statues from incident, use incidentInstance.statues. Return a list of status objects # to access derived table, from incident table use incidentInstance.incident_has_status or statusInstance.incidents statuses = association_proxy('incident_has_status', 'status',creator=lambda status: IncidentHasStatus(status=status)) def __init__(self, **kwargs): super(Incident, self).__init__(**kwargs)
class AnimeSeries(db.Model): __tablename__ = 'animeseries' id = db.Column(db.Integer, primary_key=True) animeTitle = db.Column(db.String(100), nullable=False) content = db.Column(db.Text, nullable=False) premiered = db.Column(db.Text, nullable=False) episodes = db.Column(db.Text, nullable=False, default='n/a') scored = db.Column(db.Text, nullable=False) scoredBy = db.Column(db.Text, nullable=False) thumbnail = db.Column(db.Text, nullable=False, default='thumbnail.jpg') pic1 = db.Column(db.Text, nullable=False, default='pic1.jpg') pic2 = db.Column(db.Text, nullable=False, default='pic2.jpg') briefContent = db.Column(db.Text, nullable=False) posts = db.relationship('Post', backref='posts', lazy=True) genre = db.relationship('AnimeGenre', backref='anime_genre', lazy=True) media = db.relationship('AnimeMedia', backref='anime_media', lazy=True) studio = db.relationship('AnimeStudio', backref='anime_studio', lazy=True) producer = db.relationship('AnimeProducer', backref='anime_producer', lazy=True) def __repr__(self): genreID = [] for item in self.genre: item = str(item) item = item.replace("<", "") item = item.replace(">", "") item = item.replace("AnimeGenre", "") item = item.replace(" ", "") item = item.split(",") item = item[1] genreID.append(item) return f"{self.id}" + "-" + f"{genreID}"
class Post(db.Model): id = db.Column(db.Integer, primary_key=True) author_id = db.Column(db.Integer, db.ForeignKey('profile.id', ondelete='CASCADE'), nullable=False) content = db.Column(db.String(280), nullable=False) location = db.Column(db.String(40), nullable=True) date_posted = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) image = db.Column(db.String(20), nullable=True) comments = db.relationship('Comment', cascade="all, delete-orphan", backref='post') likes = db.relationship('Profile', secondary=likes, lazy='subquery', backref=db.backref('likes', lazy=True)) def add_image(self, image_data): picture_file_name = save_image(image_data, app.config['UPLOAD_FOLDER_POSTS_IMGS'], (510, 515)) self.image = picture_file_name def delete_image(self): if self.image: delete_image(app.config['UPLOAD_FOLDER_POSTS_IMGS'], self.image) self.image = None def __repr__(self): return f"Post({self.id}, '{self.author_id}', '{self.content}', '{self.location}', '{self.date_posted}', '{self.image}')" def __str__(self): return f"Post(#{self.id})"
class Visitor(db.Model): __tablename__ = 'visitor' name = db.Column(db.String(25)) contact = db.Column(db.String(11)) place_from = db.Column(db.String(20)) timesheet = db.relationship('Timesheet_Visitor', backref='timelog') activities = db.relationship('Activity', backref='activity')
class Graduacao(db.Model): id = db.Column(db.Integer, primary_key=True) tabela1 = db.Column(db.Text) tabela2 = db.Column(db.Text) atividades = db.relationship('Eventos', backref='graduacao', lazy=True) cidade_id = db.Column(db.String(20), db.ForeignKey('campi.cidade')) dias = db.relationship('Letivos', backref='grad1', lazy=True) def __repr__(self): return f"{self.id}"
class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key = True) username = db.Column(db.String(20), unique = True, nullable = False) email = db.Column(db.String(120), unique = True, nullable = False) image_file = db.Column(db.String(20), nullable = False, default = 'default.jpg') password = db.Column(db.String(60), nullable = False) posts = db.relationship('Post', backref = 'author', lazy = True) drafts = db.relationship('Draft', backref = 'author', lazy = True) def __repr__(self): return f"User('{self.username}', '{self.email}', '{self.image_file}')"
class Course(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.Text, nullable=False) questions = db.relationship("Question", backref="course", lazy=True) mcq_questions = db.relationship("MCQQuestion", backref="course", lazy=True) user_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False) def __repr__(self): return f"Course({self.name})" def to_dict(self): return dict(id=self.id, course=self.name)
class IncidentAssignedToRelevantAgencies(db.Model): _tablename_ = "incident_assigned_to_relevant_agencies" # Attributes agency_id = db.Column(db.Integer, db.ForeignKey('relevant_agency.agencyid'), primary_key=True) incidentID = db.Column(db.Integer, db.ForeignKey('incident.incidentID'), primary_key=True) link = db.Column(db.String(255)) ackTimeStamp = db.Column(db.DateTime) # Relationships incident = db.relationship('Incident', backref=db.backref("incident_assigned_to_relevant_agencies", cascade="all, delete-orphan")) relevantAgency = db.relationship("RelevantAgency", backref=db.backref("relevant_agency"))
class Comune_Prodotto(db.Model): comune_id = db.Column('comune_id', db.Integer, db.ForeignKey('comune.id'), primary_key=True) prodotto_id = db.Column('prodotto_id', db.Integer, db.ForeignKey('prodotto.id'), primary_key=True) quantita = db.Column('quantita', db.Integer, nullable=False) comune = db.relationship("Comune", back_populates="prodotti") prodotto = db.relationship("Prodotto", back_populates="comuni")
class User(db.Model): id = db.Column(db.Integer, primary_key=True) userid = db.Column(db.String, nullable=False, unique=True) username = db.Column(db.String, index=True, nullable=False) images = db.relationship('Image', backref='author', lazy='dynamic') likes = db.relationship('Image', secondary=like, backref='liker', lazy='dynamic') def __repr__(self): return '<User {}>'.format(self.username)
class Campi(db.Model): cidade = db.Column(db.String(20), primary_key=True) senha = db.Column(db.String(20), nullable=False) email = db.Column(db.String(120)) ferias = db.relationship('Ferias', backref='campus1', lazy=True) atividades = db.relationship('Atividades', backref='campus2', lazy=True) tecnico = db.relationship('Tecnico', backref='campus3', lazy=True) calem = db.relationship('Calem', backref='campus4', lazy=True) graduacao = db.relationship('Graduacao', backref='campus5', lazy=True) def __repr__(self): return f"{self.cidade}"
class IncidentHasStatus(db.Model): __tablename__ = 'incident_has_status' statusTime = db.Column(db.DateTime, primary_key=True, nullable=False, default=sgtimestampnow) statusID = db.Column(db.Integer, db.ForeignKey('status.statusID')) incidentID = db.Column(db.Integer, db.ForeignKey('incident.incidentID')) # Relationships incident = db.relationship('Incident', backref=db.backref("incident_has_status", cascade="all, delete-orphan")) status = db.relationship("Status", backref=db.backref("incidents")) def __init__(self, **kwargs): super(IncidentHasStatus, self).__init__(**kwargs)
class User(db.Model, UserMixin): __tablename__ = "user" id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20), nullable=False, unique=True) email = db.Column(db.String(100), nullable=False, unique=True) password = db.Column(db.String(60), nullable=False) # build relationship with other forms visitors = db.relationship('Visitor', backref='user', lazy=True) records = db.relationship('VisitRecord', backref='user', lazy=True) def __repr__(self): return f"User('{self.username}','{self.email}')"
class Comune(db.Model): id = db.Column(db.Integer, primary_key=True) nome = db.Column(db.String(60), nullable=False) cap = db.Column(db.Integer, nullable=False) utenti = db.relationship('Utente', backref='comune', lazy=True) prodotti = db.relationship("Comune_Prodotto", back_populates='comune', lazy='dynamic') # donazioni = db.relationship('Prodotto', secondary=donazione, back_populates='donazioni', lazy=True) # ritiri = db.relationship('Prodotto', secondary=ritiro, back_populates='ritiri', lazy=True) def __repr__(self): return f"Comune('{self.id}', '{self.nome}', '{self.cap}')"
class Card(db.Model): __tablename__ = 'card' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(120), unique=True, nullable=False) power = db.Column(db.Integer) toughness = db.Column(db.Integer) manaCost = db.Column(db.String(10)) image = db.Column(db.String(80), nullable=False, default='default_card.jpg') card_types = db.relationship('CardType', secondary=card_type_assoc, backref=db.backref('cards'), lazy='dynamic') card_sub_types = db.relationship('CardSubType', secondary=card_sub_type_assoc, backref=db.backref('cards'), lazy='dynamic') def __repr__(self): return 'Card:' + self.name
class Books(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(100), nullable=False) authors = db.relationship('Author', secondary=authors, backref=db.backref('authors', lazy='dynamic')) published_date = db.Column(db.String(5), nullable=True) categories = db.relationship('Category', secondary=categories, backref=db.backref('categories', lazy='dynamic')) average_rating = db.Column(db.String(10), nullable=True) ratings_count = db.Column(db.String(10), nullable=True) thumblnail = db.Column(db.String(100), nullable=True)
class Post(db.Model): __tablename__ = 'posts' pid = db.Column(db.Integer, primary_key=True) content = db.Column(db.Text, nullable=False) media = db.Column(db.String(32), nullable=True) date_posted = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) user_id = db.Column(db.Integer, db.ForeignKey('users.uid'), nullable=False) liked = db.relationship("User", secondary=likes) comments = db.relationship('Comment', backref='post', lazy=True) notifs = db.relationship('Notif', backref='post', lazy=True) def get_likes_count(self): return len(self.liked) def user_liked(self, user): return user in self.liked def like_post(self, user): if user not in self.liked: self.liked.append(user) return "like" else: self.unlike_post(user) return "unlike" def unlike_post(self, user): self.liked.remove(user) def comments_count(self): return len(self.comments) def get_comments(self, limit=0): if limit > 0: return self.comments[-limit:] def get_timeago(self): now = datetime.now() return timeago.format(self.date_posted, now) def __repr__(self): return f"Post('{self.content}', '{self.date_posted}')"
class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20), nullable=False) email = db.Column(db.String(120), unique=True, nullable=False) tel_nr = db.Column(db.String(9), unique=True, nullable=False) age = db.Column(db.String(2), nullable=False) password = db.Column(db.String(60), nullable=False) role = db.Column(db.String(5), default='0') posts = db.relationship('Post', backref='author', lazy=True) info = db.relationship('Info', backref='author') photo = db.relationship('Photo', backref='author') def __repr__(self): return f"User('Imię: {self.username}', 'Wiek: {self.age}', 'Tel: {self.tel_nr}', 'ID: {self.id}')"
class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) full_name = db.Column(db.String(40), nullable=False, default='Not yet provided') username = db.Column(db.String(21), unique=True, nullable=False) email = db.Column(db.String(60), unique=True, nullable=False) image_file = db.Column(db.String(20), nullable=False, default='default.jpg') password = db.Column(db.String(60), nullable=False) about = db.Column(db.Text, nullable=False, default='Not yet provided') internet_points = db.Column(db.Integer, nullable=False, default=0) posts = db.relationship('Post', backref='author', lazy=True) def get_reset_token(self, expires_sec=3600): s = Serializer(app.config['SECRET_KEY'], expires_sec) return s.dumps({'user_id': self.id}).decode('utf-8') @staticmethod def verify_reset_token(token): s = Serializer(app.config['SECRET_KEY']) try: user_id = s.loads(token)['user_id'] except: return None return User.query.get(user_id) def __repr__(self): return f"User('{self.username}', '{self.full_name}', '{self.email}', '{self.image_file}', '{self.about[:16]}...')"
class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20), unique=True, nullable=False) email = db.Column(db.String(120), unique=True, nullable=False) image_file = db.Column(db.String(20), nullable=False, default="default.svg") password = db.Column(db.String(60), nullable=False) courses = db.relationship("Course", backref="teacher", lazy=True) def get_reset_token(self, expires_sec=86400): s = Serializer(current_app.config["SECRET_KEY"], expires_sec) return s.dumps({"user_id": self.id}).decode("utf-8") @staticmethod def verify_reset_token(token): s = Serializer(current_app.config["SECRET_KEY"]) try: user_id = s.loads(token)["user_id"] except: return None return User.query.get(user_id) def __repr__(self): return f"User({self.username}, {self.email}, {self.image_file})" def to_dict(self): return dict( id=self.id, username=self.username, email=self.email, image_file=self.image_file, )
class User(UserMixin, db.Model): id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(100), unique=True) image = db.Column(db.Text(), default='index.png') password = db.Column(db.String(100)) name = db.Column(db.String(1000)) posts = db.relationship('Post', backref='user', lazy=True)
class Ritiro(db.Model): utente_id = db.Column('utente_id', db.Integer, db.ForeignKey('utente.id'), primary_key=True) prodotto_id = db.Column('prodotto_id', db.Integer, db.ForeignKey('prodotto.id'), primary_key=True) quantita = db.Column('quantita', db.Integer, nullable=False) data_ora = db.Column('data_ora', db.DateTime, default=datetime.utcnow, primary_key=True) bisognoso = db.relationship("Utente", back_populates="prodotti_ritirati") prodotto_ritirato = db.relationship("Prodotto", back_populates="bisognosi")
class Post(db.Model): id = db.Column(db.Integer, primary_key=True) ques = db.Column(db.String(150), nullable=False) answers = db.relationship('Ans', backref=db.backref('question'), lazy=True) def __repr__(self): return f"post('{self.ques}')"
class Project(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(60), nullable=False) date_posted = db.Column(db.DateTime) upload_file = db.Column(db.String(20), nullable=False) description = db.Column(db.Text(1500), nullable=False) optional_link = db.Column(db.String) creators_num = db.Column(db.Integer, nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) last_editor = db.Column(db.String) score_points_pool = db.Column(db.Integer, default=0) score_points_pool_shuffled = db.Column(db.Integer, default=0) score_pool_per_project = db.Column(db.Integer, default=0) score_admin = db.Column(db.Integer, default=0) score_admin_improvement = db.Column(db.Integer, default=0) user_distinctions = db.Column(db.Integer, default=0) admin_distinction = db.Column(db.Boolean, default=False) comments = db.relationship('Comments', backref='project', lazy=True, cascade="all, delete") date_posted_improvement = db.Column(db.DateTime) title_improvement = db.Column(db.String(60)) upload_file_improvement = db.Column(db.String(20)) description_improvement = db.Column(db.Text(1500)) optional_link_improvement = db.Column(db.String) def __repr__(self): return f"Project('{self.title}', 'author_id={self.user_id}')"
class EquipmentTypeModel(db.Model, BaseModel): # The name of the table at the data base. __tablename__ = TableNames.S_EQUIPMENT_TYPE # The table columns. type_id = db.Column(db.String(50), primary_key=True) description = db.Column(db.String(500), nullable=True) equipments = db.relationship(RelationShip.EQUIPMENT, backref="info", cascade="save-update, merge, delete", lazy=True) def __repr__(self): return "EquipmentTagsModel(type_id={})".format(self.type_id) def to_dict(self): """ Convert EquipmentTagsModel into a dictionary, this way we can convert it to a JSON response. :return: A clean dictionary form of this model. """ # convert columns to dict dict_representation = super().to_dict() # add additional values for the dictionary. dict_representation["equipments"] = [ eq.to_dict() for eq in self.equipments ] return dict_representation
class Activity(db.Model): __tablename__ = "activity" visitor_id = db.Column(db.Integer, db.ForeignKey('visitor.id')) visiting_purpose = db.Column(db.String(50)) visiting_employee = db.Column(db.Integer, db.ForeignKey('employee.id')) visiting_department = db.Column(db.Integer, db.ForeignKey('department.id')) timesheet = db.relationship('Timesheet_Visitor', backref="timelog")
class User(db.Model,UserMixin): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20), unique=True, nullable=False) email = db.Column(db.String(120), unique=True, nullable=False) password = db.Column(db.String(60), nullable=False) entry = db.relationship('graphData',backref='user', lazy=True) def __repr__(self): return f"User('{self.username}', '{self.entry}')"
class User(db.Model, UserMixin): __table_args__ = {'sqlite_autoincrement': True} id = db.Column(db.Integer, primary_key=True) login = db.Column(db.String(20), unique=True, nullable=False) password = db.Column(db.String(30)) is_admin = db.Column(db.Boolean, nullable=False, default=False) # user_role = db.Column(db.String(30)) project = db.relationship('Project', backref='author', uselist=False, lazy=True, cascade="all, delete") group_id = db.Column(db.Integer, db.ForeignKey('group.id'), nullable=True) did_rate = db.Column(db.Boolean, default=False) section_number = db.Column(db.Integer) admin_groups = db.relationship('Group', foreign_keys="[Group.admin_id]", backref='admin', lazy=True) # add cascade? rating_type = db.Column(db.String(50), nullable=True) # 'points_pool', 'points_pool_shuffled', 'pool_per_project' comments = db.relationship('Comments', backref='author', lazy=True) def __repr__(self): return f"User('{self.login}', admin={self.is_admin})"