Re: [sqlalchemy] Abstracting common hybrid properties

2019-09-23 Thread Mike Bayer
easy enough to create a function def dict_getter(attr, key): @hybrid_property def get(self): return getattr(self, attr).get(key) @get.expression def get(self): return getattr(self, attr)[key] return get class User(Base): phone_number_2= dict_getter("details", "phone_num_2") probably

[sqlalchemy] Abstracting common hybrid properties

2019-09-23 Thread Gary L
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