class TObservations(DB.Model): __tablename__ = "t_observations" __table_args__ = {"schema": "gn_monitoring"} id_observation = DB.Column(DB.Integer, primary_key=True, nullable=False, unique=True) id_base_visit = DB.Column( DB.ForeignKey('gn_monitoring.t_base_visits.id_base_visit')) cd_nom = DB.Column(DB.Integer) comments = DB.Column(DB.String) uuid_observation = DB.Column(UUID(as_uuid=True), default=uuid4) medias = DB.relationship( TMedias, lazy='joined', primaryjoin=(TMedias.uuid_attached_row == uuid_observation), foreign_keys=[TMedias.uuid_attached_row]) t_observation_details = DB.relation( TMonitoringObservationDetails, primaryjoin=( id_observation == TMonitoringObservationDetails.id_observation), foreign_keys=[TMonitoringObservationDetails.id_observation], cascade="all,delete")
class TMonitoringVisits(TBaseVisits): __tablename__ = "t_visit_complements" __table_args__ = {"schema": "gn_monitoring"} __mapper_args__ = { 'polymorphic_identity': 'monitoring_visit', } id_base_visit = DB.Column( DB.ForeignKey('gn_monitoring.t_base_visits.id_base_visit'), nullable=False, primary_key=True) data = DB.Column(JSONB) medias = DB.relationship( TMedias, lazy='joined', primaryjoin=(TMedias.uuid_attached_row == TBaseVisits.uuid_base_visit), foreign_keys=[TMedias.uuid_attached_row]) observers = DB.relationship(User, lazy='joined', secondary=corVisitObserver) observations = DB.relation( "TMonitoringObservations", lazy='select', primaryjoin=(TObservations.id_base_visit == TBaseVisits.id_base_visit), foreign_keys=[TObservations.id_base_visit], cascade="all,delete") nb_observations = column_property( select([func.count(TObservations.id_base_visit)]).\ where(TObservations.id_base_visit==id_base_visit) )
class TMonitoringVisits(TBaseVisits): __tablename__ = "t_visit_complements" __table_args__ = {"schema": "gn_monitoring"} __mapper_args__ = { 'polymorphic_identity': 'monitoring_visit', } id_base_visit = DB.Column( DB.ForeignKey('gn_monitoring.t_base_visits.id_base_visit'), nullable=False, primary_key=True) data = DB.Column(JSONB) medias = DB.relationship( TMedias, primaryjoin=(TMedias.uuid_attached_row == TBaseVisits.uuid_base_visit), foreign_keys=[TMedias.uuid_attached_row]) observations = DB.relation( "TMonitoringObservations", primaryjoin=(TObservations.id_base_visit == TBaseVisits.id_base_visit), foreign_keys=[TObservations.id_base_visit], cascade="all,delete") @hybrid_property def nb_observations(self): return len(self.observations)