I have a small model with a 'json' column called details and several hybrid 
properties to abstract getting from it safely:

User(Base):

   @hybrid_property
   def phone_number_2(self):
       return self.details.get('phone_num_2')

However when I use this in a query, in the class context, I get an error as 
sqlalchemy does not understand the .get method for python dictionaries. 
That's all fine as I can define hybrid expressions as such:

@phone_numer_2.expression
def phone_number_2(cls):
    return self.details['phone_num_2']


This works fine but the only issue is I have a lot of similar columns I'd 
like to pull out and writing the expression every time seems cumbersome. Is 
there a convenient way to abstract this in Sqlalchemy? Some way I could 
tell sqlalchemy what .get means?

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/da8d4fc0-7c99-470c-b710-f3a238fc823a%40googlegroups.com.

Reply via email to