class AnimeStudio(db.Model): animeseries_id = db.Column(db.Integer, db.ForeignKey('animeseries.id'), primary_key=True) studio_id = db.Column(db.Integer, db.ForeignKey('studio.id'), primary_key=True)
class AnimeProducer(db.Model): animeseries_id = db.Column(db.Integer, db.ForeignKey('animeseries.id'), primary_key=True) producer_id = db.Column(db.Integer, db.ForeignKey('producer.id'), primary_key=True)
class Drone_DBModel(db.Model): __tablename__ = 'drones' # Here we define db.Columns for the table person # Notice that each db.Column is also a normal Python instance attribute. id = db.Column(db.Text, primary_key=True) owner = db.Column(db.Text, db.ForeignKey('users.id', ondelete='CASCADE')) description = db.Column(db.Text) live_data = db.Column(db.Text, db.ForeignKey('live_drone_data.id', ondelete='CASCADE')) manufacturer = db.Column(db.Text) type = db.Column(db.Text) color = db.Column(db.Text) number_of_blades = db.Column(db.Integer) def __init__(self, id, owner, description, live_data, manufacturer = "", type="", color="", number_of_blades = 0): self.id = id self.owner = owner self.description = description self.live_data = live_data self.manufacturer = manufacturer self.type = type self.color = color self.number_of_blades = number_of_blades
class AnimeGenre(db.Model): animeseries_id = db.Column(db.Integer, db.ForeignKey('animeseries.id'), primary_key=True) genre_id = db.Column(db.Integer, db.ForeignKey('genre.id'), primary_key=True)
class RolesRightsModel(db.Model, BaseModel): # The name of the table at the data base. __tablename__ = TableNames.T_ROLES_RIGHTS # The table columns. role_id = db.Column(db.String(50), db.ForeignKey(TableNames.S_ROLES + ".role_id"), primary_key=True) right_id = db.Column(db.String(50), db.ForeignKey(TableNames.S_RIGHTS + ".right_id"), primary_key=True) def __repr__(self): return "RolesRights(role_id={}, right_id={})".format(self.role_id, self.right_id) # Queries for this model. @classmethod def get_rights_by_role(cls, role_id: str): """ Get the a list of right ids for this role. :param role_id: The role id. :return: A list of right ids for this role. """ roles_rights: List[RolesRightsModel] = cls.find_by(role_id=role_id, get_first=False) if roles_rights: return [rr.right_id for rr in roles_rights] return None
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 AnimeMedia(db.Model): animeseries_id = db.Column(db.Integer, db.ForeignKey('animeseries.id'), primary_key=True) media_id = db.Column(db.Integer, db.ForeignKey('media.id'), primary_key=True)
class Comments(db.Model): id = db.Column(db.Integer, primary_key=True) comment_star_1 = db.Column(db.Text(1000), nullable=False) comment_star_2 = db.Column(db.Text(1000), nullable=False) comment_wish = db.Column(db.Text(1000), nullable=False) second_iteration = db.Column(db.Boolean, default=False) project_id = db.Column(db.Integer, db.ForeignKey('project.id'), nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
class Ans(db.Model): id = db.Column(db.Integer, primary_key=True) sol = db.Column(db.String(500), nullable=False) post_id = db.Column(db.Integer, db.ForeignKey('post.id'), nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) def __repr__(self): return f"'{self.post_id}','{self.sol}'"
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 UserPassList(db.Model): user_id = db.Column(db.Integer, db.ForeignKey('user.id'), primary_key=True) animeseries_id = db.Column(db.Integer, db.ForeignKey('animeseries.id'), primary_key=True) def __repr__(self): return f"{self.animeseries_id}"
class PostLikes(db.Model): id = db.Column(db.Integer, primary_key = True) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable = False) post_id = db.Column(db.Integer, db.ForeignKey('post.id'), nullable = False) def __repr__(self): return f"PostLikes('{self.user_id}', '{self.post_id}')"
class ProjectMembers(db.Model): id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) project_id = db.Column(db.Integer, db.ForeignKey('project.id'), nullable=False) def __repr__(self): return f"ProjectMembers('{self.user_id}', '{self.user_id}', '{self.project_id}')"
class Timesheet_Visitor(db.Model): __tablename__ = 'timesheet_visitor' visitor_id = db.Column(db.Integer, db.ForeignKey('visitor.id')) activity_id = db.Column(db.Integer, db.ForeignKey('activity.id')) date = db.Column(db.Date) in_time = db.Column(db.Time) out_time = db.Column(db.Time) duration = db.Column(db.String(20))
class Comment(db.Model): __tablename__ = 'comments' cid = db.Column(db.Integer, primary_key=True) content = db.Column(db.Text, nullable=False) post_id = db.Column(db.Integer, db.ForeignKey('posts.pid'), nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('users.uid'), nullable=False) date_posted = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) def __repr__(self): return f"Comment({self.post_id}, {self.user_id}, '{self.content}', '{self.date_posted}')"
class Follow_DBModel(db.Model): __tablename__ = 'follows_db' id = db.Column(db.Text, db.ForeignKey('users.id', ondelete='CASCADE'), primary_key=True) followers = db.Column(db.Text, db.ForeignKey('users.id', ondelete='CASCADE'), primary_key=True) def __init__(self, i, followers): self.id = i self.followers = followers
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 Post(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(100), nullable=False) date_posted = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) content = db.Column(db.Text, nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=True) animeseries_id = db.Column(db.Integer, db.ForeignKey('animeseries.id')) def __repr__(self): return f"User: {self.author.username}" + "\n" + f" Title: {self.title}" + "\n" + f"Review: {self.content}"
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 ProjectMessages(db.Model): id = db.Column(db.Integer, primary_key=True) date_posted = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) project_id = db.Column(db.Integer, db.ForeignKey('project.id'), nullable=False) message = db.Column(db.String(1000), nullable=True) def __repr__(self): return f"ProjectMessages('{self.user_id}', '{self.project_id}')"
class UserRightModel(db.Model, BaseModel): # The name of the table at the data base. __tablename__ = TableNames.T_USER_RIGHTS # The table columns. user_id = db.Column(db.String(16), db.ForeignKey(TableNames.T_USER + ".id"), primary_key=True) right_id = db.Column(db.String(50), db.ForeignKey(TableNames.S_RIGHTS + ".right_id"), primary_key=True) lastchange_by = db.Column(db.String(16), unique=False, nullable=True) lastchange_at = db.Column(db.DateTime, default=datetime.utcnow) def __repr__(self): return "UserRight(id={}, right={})".format(self.user_id, self.right_id)
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 DB_ProductImage(db.Model): __tablename__ = 'product' image_name = db.Column(db.Text, primary_key=True) product_name = db.Column(db.Text, db.ForeignKey('product.name', ondelete = 'CASCADE')) product_color = db.Column(db.Text, , db.ForeignKey('product.color', ondelete = 'CASCADE')) def __init__(self, name, color, stock, price): self.name = name self.color = color self.stock = stock self.price = price def __repr__(self): return '<id {}>'.format(self.id)
class VisitRecord(db.Model): __tablename__ = "visit_record" id = db.Column(db.Integer, primary_key=True) # datatime.ucnow pass in a function as an argument photo = db.Column(db.String(20), nullable=False) date_visited = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) visitor_id = db.Column(db.Integer, db.ForeignKey('visitor.id')) def __repr__(self): return f"Record(visitor:'{self.visitor_id}',date:'{self.date_visited}')"
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 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 FileTransferredModel(db.Model, BaseModel): # The name of the table at the data base. __tablename__ = TableNames.T_TRANSFERRED_FILES # The table columns. id = db.Column(db.String(50), primary_key=True) status_id = db.Column( db.String(50), db.ForeignKey(TableNames.S_TRANSFERRED_STATUS + ".id")) transferred_by = db.Column(db.String(50), unique=False, nullable=False) transferred_at = db.Column(db.DateTime, default=datetime.utcnow, nullable=False) def __repr__(self): return "FileTransferredModel(id={}, status_id={}, transferred_by={}, transferred_at={})"\ .format(self.id, self.status_id, self.transferred_by, self.transferred_at) def save(self): if current_user: self.transferred_by = current_user.username else: self.transferred_by = "Unknown" super().save() def update(self, status_id: str, transferred_at: datetime): self.status_id = status_id self.transferred_at = transferred_at self.save()
class Posts(db.Model): sno = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(100), nullable=False) content = db.Column(db.String(500)) date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) slug = db.Column(db.String(30), nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
class post(db.Model): id= db.Column(db.Integer, primary_key=True) picture = db.Column(db.String(20),nullable = False) title = db.Column(db.String(20), nullable = False) description = db.Column(db.String(150)) author = db.Column(db.String(60)) postedBy = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
class Question(db.Model): id = db.Column(db.Integer, primary_key=True) question = db.Column(db.JSON, nullable=False) mark = db.Column(db.Integer, nullable=False) difficulty = db.Column(db.Enum(DifficultyEnum), nullable=False) cognitive_level = db.Column( db.Enum(CognitiveEnum), nullable=False, ) question_type = db.Column(db.Enum(QuestionTypeEnum), nullable=False) imp = db.Column(db.Boolean, default=False) is_asked = db.Column(db.Boolean, default=False) unit_id = db.Column(db.Integer, db.ForeignKey("unit.id"), nullable=False) def __repr__(self): return (f"Question({self.question['question']}," f" {self.mark}," f" {self.difficulty.name}," f" {self.cognitive_level.name}," f" {self.question_type.name}," f" {self.imp})") def to_dict(self): data = dict( id=self.id, mark=self.mark, difficulty=self.difficulty.name, cognitive_level=self.cognitive_level.name, question_type=self.question_type.name, imp=self.imp, ) data.update(self.question) return data