あるフリーランスエンジニアの色んなメモ!! ITスキル・ライフハックとか

Django:ChoiceFieldの選択肢を設定する

実装例

初期化時

my_field = MyChoiceField(
    ...
    choices=[
        (optionのvalue, optionのinnerText),
        ...
    ]
)

初期化時以外

form.fields.get(フィールド名))._set_choices(
    [
        (optionのvalue, optionのinnerText),
        ...
    ]
)
comments powered by Disqus