On Mon, Oct 3, 2016 at 11:43 AM, Jinghui Niu wrote:
> This really helps. Thank you Simon! I still have a couple of smaller
> questions.
>
>> When you access .fullname, the "self" parameter is now the
>> *class*, so self.firstname and self.lastname are SQLAlchemy column
>>
This really helps. Thank you Simon! I still have a couple of smaller
questions.
When you access .fullname, the "self" parameter is now the
> *class*, so self.firstname and self.lastname are SQLAlchemy column
> properties.
Here by *column properties* do you mean the object returned by
The first example from the docs is illustrating the most simple case,
where the function happens to work at both the instance and class
level. Here's the example:
class User(Base):
__tablename__ = 'user'
id = Column(Integer, primary_key=True)
firstname = Column(String(50))
>
> User.firstname is not the value from any particular row - it's the
> (ORM-level) column object.
It's a little abstruse here that a ORM-level instrumented column object,
such as User.firstname works, but a true Column object, such as
User.__table__.c.firstname doesn't. Maybe I misunderstood
Thank you Simon. Your explanation helps me understand this quite a lot.
Sometimes the documentation is so terse that only when you fully understand
the subject then you can understand it by reading it:) But still if I want
to implement this hybrid property from the query level, how would you
On Mon, Oct 3, 2016 at 7:17 AM, Jinghui Niu wrote:
> I have a ledger table and a corresponding python class. I defined the model
> using SQLAlchemy, as follows,
>
> class Ledger(Base):
> __tablename__ = 'ledger'
>
> currency_exchange_rate_lookup = {('CNY', 'CAD'):
I have a ledger table and a corresponding python class. I defined the model
using SQLAlchemy, as follows,
class Ledger(Base):
__tablename__ = 'ledger'
currency_exchange_rate_lookup = {('CNY', 'CAD'): 0.2}
amount = Column(Numeric(10, 2), nullable=False)
currency =