0
新しいグループを追加したいのですが、先生のためにテーブルの中にあるリストから選択する必要があります。
テーブル:教師、グループ
関係:多くのグループ新しいグループを追加するにはどうすればいいですか教師はリストから来る必要があります
models.py
class Teacher(models.Model):
name = models.CharField(max_length=100)
def __str__(self):
return '%s' % (self.name)
class Group(models.Model):
name = models.CharField(max_length=100)
teacher = models.ForeignKey(Leraren, on_delete=models.CASCADE)
def __str__(self):
return '%s %s' % (self.name, self.teacher)
forms.py
class TeacherForm(forms.Form):
name = forms.CharField(required=True, label='name', max_length=100)
class GroupForm(forms.Form):
name = forms.CharField(required=True, label='name', max_length=100)
teacher = # choose from list of teachers that are in the db Teachers #
これを行うには必要性をtheresの、何が起こりますか?何がうまくいかない?あなたは何を期待していますか? – wwii
フォームアクションは投稿であり、リストの名前は先生です。その投稿名の変数を取得するために、forms.pyに何を書かなければならないのですか? – EnzoTrompeneers