Closed marplatense closed 10 years ago
formalchemy works by analyzing sqlalchemy's internal data structures. The problem is that hybrid_property is just a utility function which implements a fancy way of generating a property class; it doesn't hook into sqlalchemy at all, so formalchemy doesn't see it.
Therefore, you need to create the 'gender' attribute yourself. This is simple enough:
from formalchemy.fields import AttributeField
t = Test()
fs1 = FieldSet(t)
gf = AttributeField(Test.gender,fs1)
gf.name="gender"
fs1.append(gf)
fs1.configure(include=[fs1.name, fs1.gender])
fs1.render()
I just hit this same problem, what's odd is that older versions of FormAlchmey did seem to work with synonyms and hybrid_property but newer versions don't. I'm not sure exactly where the break happened but FormAlchemy==1.4.3 does allow them. In the following example 'password' is a synonym for _password. The only difference between the two was moving from my pinned FA version to the latest.
1.4.3
>>> from formalchemy import FieldSet
>>> fs = FieldSet(User)
>>> print fs.password
AttributeField(password)
1.5.5
>>> from formalchemy import FieldSet
>>> fs = FieldSet(User)
>>> print fs.password
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/share/ps/venv/qs2/local/lib/python2.7/site-packages/formalchemy/forms.py", line 799, in __getattr__
raise AttributeError(attrname)
AttributeError: password
Created a pull request #64 with changes restoring the older synonym / hybrid_property exposing behavior.
I was under the impression issue 11 would include hybrid_properties but I cannot make them work. Consider the following example where gender is a synonym for _gender:
When I execute it, I'm getting:
If I use _gender as the included field, of course it works however it bypasses my property control.
TIA, Mariano