[sqlalchemy] How to format class property as another accessible property

2017-06-07 Thread GMS
I am sure this is easier than I am making it, but I just want to add a 
property to a class so that decimal representations get truncated at 3 
decimal digits.

My class is this:

class Measures(Model):
__tablename__ = 'xcelera_measures'
id = Column(Numeric, primary_key=True)
studyidk = Column(Numeric, ForeignKey('xcel.studyidk'))
xceleragroup = relationship("Xcelera")
explainstring = Column(String(255))
mrn = Column(String(255))
value = Column(Numeric)

__mapper_args__ = {
"order_by": [mrn]
}


and 'value' is the property/attribute that I want to also have a truncated 
version available in the class. 

I tried adding this to the class value_new = column_property("%.3f" % 
value())

but got an error that

value_new = column_property("%.3f" % value)

TypeError: float argument required, not Column

I also tried this as a hybrid_property, but I don't think I was using it 
correctly.

All I want to do is have the truncated version of my attribute available in 
my class.

Thanks!

Greg--


-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] Grouped data in a Flask/SQLAlchemy class

2017-03-01 Thread GMS
I have the following class models:

  
  class DiagnosisDetail(Model):
__tablename__ = 'vw_svc_diagnosis'
diagnosis_id = Column(String(32), primary_key=True)
first_name = Column(String(255))
last_name = Column(String(255))
mrn = Column(String(255))
dx_code = Column(String(255))
dx_id = Column(String(255), ForeignKey('dx_group.dx_id'))
diagnosisgroup = relationship("DiagnosisGroup")
dx_code_type = Column(String(255))
dx_name = Column(String(255))

__mapper_args__ = {
 "order_by":[mrn, dx_name]
   }

class DiagnosisGroup(Model):
__tablename__ = 'diagnosis_group'
dx_id = Column(String(32), primary_key=True)
mrn = Column(String(255))
dx_code = Column(String(255))
dx_code_type = Column(String(255))
dx_name = Column(String(255))
diagnosis_datetime = Column(DateTime)

__mapper_args__ = {
 "order_by":[mrn, dx_name]
   }



where the underlying tables for DiagnosisGroup and DiagnosisDetail are SQL 
views. DiagnosisGroup is so that I can have a more succinct view of the 
data, since a patient can have the same diagnosis many times. I am 
wondering if there is a way to do this within the class structure  instead 
of at the db server? I do not wish to do this through any ORM session 
queries, since these two classes have distinct use cases where they bind to 
wtform views. Thus, I would like to inherit the properties of these two 
classes from another distinct class. 

I have not been able to find anything like this, short of 
[create-column-properties-that-use-a-groupby][1] 
,
 
but this uses session queries to achieve the result. I would like to keep 
everything within the class itself through inheritance of the 
DiagnosisDetail class.

Note: the primary key for DiagnosisGroup, is a concatenation of dx_code and 
another field patient_id. Groupings thus are unique. I do also need the FK 
relation back to the DiagnosisDetail class, which leads me to believe there 
should be three classes, where the two above classes inherit their 
properties from a parent class.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] Grouped data in a Flask/SQLAlchemy class

2017-03-01 Thread GMS
I have the following class models:

  
  class DiagnosisDetail(Model):
__tablename__ = 'vw_svc_diagnosis'
diagnosis_id = Column(String(32), primary_key=True)
first_name = Column(String(255))
last_name = Column(String(255))
mrn = Column(String(255))
dx_code = Column(String(255))
dx_id = Column(String(255), ForeignKey('dx_group.dx_id'))
diagnosisgroup = relationship("DiagnosisGroup")
dx_code_type = Column(String(255))
dx_name = Column(String(255))

__mapper_args__ = {
 "order_by":[mrn, dx_name]
   }

class DiagnosisGroup(Model):
__tablename__ = 'diagnosis_group'
dx_id = Column(String(32), primary_key=True)
mrn = Column(String(255))
dx_code = Column(String(255))
dx_code_type = Column(String(255))
dx_name = Column(String(255))
diagnosis_datetime = Column(DateTime)

__mapper_args__ = {
 "order_by":[mrn, dx_name]
   }



where the underlying tables for DiagnosisGroup and DiagnosisDetail, 
diagnosis_group, are SQL views. DiagnosisGroup is so that I can have a more 
succinct view of the data, since a patient can have the same dx_code many 
times. I am wondering if there is a way to do this within the class 
structure for , instead of at the db server? I do not wish to do this 
through any ORM session queries, since these two classes have distinct use 
cases where they bind to wtform views. Thus, I would like to inherit the 
properties of these two classes from another distinct class. 

I have not been able to find anything like this, short of 
[create-column-properties-that-use-a-groupby][1] 
,
 
but this uses session queries to achieve the result. I would like to keep 
everything within the class itself through inheritance of the 
DiagnosisDetail class.

Note: the primary key for DiagnosisGroup, is a concatenation of dx_code and 
another field patient_id. Groupings thus are unique. I do also need the FK 
relation back to the DiagnosisDetail class, which leads me to believe there 
should be three classes, where the two above classes inherit their 
properties from a parent class.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.