私がやろうとしているのは、formalchemy1.3.5を使用した辞書を使用してドロップダウンリストの値を設定することだけです。
ドキュメントには次のように書かれています。
オプションパラメータを使用するメソッドは、これらのオプションを指定するいくつかの方法を受け入れます。
- SQLAlchemyオブジェクトの反復可能。各オブジェクトのstr()が説明になり、主キーが値になります
- SQLAlchemyクエリ。クエリはall()で実行され、返されたオブジェクトは上記のように評価されます
- (説明、値)ペアの反復可能
- {説明:値}ペアの辞書
ここで説明するように辞書を作成します。
Location = model.meta.Session.query(model.Location)
cityCodes = {}
for row in Location:
cityCodes.update({row.city : str(row.location_code)})
そしてそれを含めます:
EmpsPerson.wiw_location_code.label('Location').dropdown(options = cityCodes),
ただし、値はまだ説明として設定されています。
<option value="Dubai">Dubai</option>
<option value="Portsmouth">Portsmouth</option>
<option value="Toulouse">Toulouse</option>
<option value="Singapore">Singapore</option>
解決済み:
したがって、この問題を修正するために、私は今使用しました:
for row in Location:
cityCodes.append([row.city,int(row.location_code)])
EmpsPerson.location_code.label('Location').dropdown(options=cityCodes)