The error from the log was fixed by adding DBSession parameter to form constructor. However, the dropbox still contained only numeric database IDs, not the data I wanted and _my_update_params() is still never called. The code looks like:
class MpsicField(PropertySingleSelectField):
def _my_update_params(self, d, nullable=False):
items = DBSession.query(Item).filter(Item.isopen==True).all()
options = [(item.item_id, item.getDisplayName())
for item in items]
d['options']= options
return d
class OrderForm(AddRecordForm):
__model__=Order
__omit_fields__ = ['dateCreated', 'dateExpires','tx_id','status','address','currency','user','trades']
__dropdown_field_names__ = ['account']
__field_order__ =['account']
account = MpsicField
I had to overload prepare() method to get my data into the dropbox.
Another problem: If I want the dropbox to be custom field (not found in Order model), it gets completely ignored and nothing is rendered. I tried this:
class OrderForm(AddRecordForm):
__model__=Order
__omit_fields__ = ['dateCreated', 'dateExpires','tx_id','status','address','currency','user','trades','account']
__dropdown_field_names__ = ['item']
__field_order__ =['item']
item = MpsicField
Dňa pondelok, 20. augusta 2012 19:05:14 UTC+2 Juraj Variny napísal(-a):