は、私は次のモデル事前移入なMultipleChoiceFieldジャンゴ
class Application(models.Model):
occupation = models.TextField()
を持っていると言うと、私は(管理者を経由して例えば)インスタンスでそれを使用する場合の選択肢が選択されていない
class ApplicationForm(forms.ModelForm):
def __init__(self, *args, **kwargs)
super().__init__(*args, **kwargs)
self.fields['occupation'] = forms.MultipleChoiceField(choices=OCCUPATION_CHOICES, widget=CheckboxSelectMultiple)
class Meta:
model = Application
を形成することができます。
私は間違っていますか?
編集:明確化:私はいくつかの選択肢を選択した場合、私はそれがデータを保存し提出するヒット。彼らはデータベースの['undergraduate', 'postdoc']
のように見えます。しかし、彼らはもはやフォームでチェックされていません。
あなたの 'super'呼び出しが間違っています。' super(ApplicationForm、self).__ init __(* args、** kwargs) ' – RodrigoDela
いいえ、python3ではそう書ける必要はありません。 https://docs.python.org/3/library/functions.html#super – Zoli
あなたの 'Application'モデルの' occupation'フィールドに 'choices = OCCUPATION_CHOICES'を追加するのを忘れました。 – RodrigoDela