On 06/07/2017 02:31 PM, GMS wrote:
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)
"%" is a Python function, that doesn't execute on the database. This
works as a normal Python descriptor:
class MyClass(Base):
# ...
@property
def value_new(self):
return "%.3f" % self.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
<mailto:sqlalchemy+unsubscr...@googlegroups.com>.
To post to this group, send email to sqlalchemy@googlegroups.com
<mailto:sqlalchemy@googlegroups.com>.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
--
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.