Open SavinaRoja opened 4 years ago
Figured out the issue with the setter, SQLAlchemy was not picking up the changes without this alteration to the model:
from sqlalchemy.ext.mutable import MutableDict
...
class Animal(Base):
...
# name_translations = Column(HSTORE) # not this
name_translations = Column(MutableDict.as_mutable(HSTORE)) # instead this
...
Hi there, looking for some guidance on this subject, as I am trying to implement a feature to enable translation of database values in a pyramid web application. The demonstration of translation via postgresql hstore in i18n.py here is intriguing and I was hoping to draw some inspiration.
In the context of my application, I cannot make any assumptions about the locales to be used, so my models themselves must be locale-agnostic. Consider the following model code:
Since this is a web application, the selection of the locale is quite dynamic: checking the accept-language header, cookie, request param, etc. Details aside, the locale is set as a property on a request object which is passed to a request handler. So the possible view code for this might look like:
I have been trying to prototype this and have some limited success. Here is the present code to implement
translation_hybridize
:One problem with the code at this time is that I must use explicit calls to
fget
,expr
, andfset
. Consider the following script:I am also presently still troubleshooting why the setter does not appear to work.
Any guidance on the overall formulation and syntax of this would be great to avoid the explicit calls would be great. I would be happy to contribute anything further to the project if it might be helpful to others.