我有一个具有以下型号的应用程序
models.py
class Student (models.Model):
first_name = models.CharField(max_length=40, default='')
second_name = models.CharField(max_length=40, default='')
#more fields here
class Paper (models.Model):
#more fields here
student = models.ForeignKey(Student)
class StudentPayment(models.Model):
student = models.ForeignKey(Student)
paper = models.ForeignKey(Paper)
我已经创建了我的 ModelForms 以非常简单的方式添加新学生和论文
#forms.py
class StudentForm(forms.ModelForm):
class Meta:
model = Student
class PaperForm(forms.ModelForms):
class Meta:
model = Paper
class StudentPaymentForm(forms.ModelForms):
class Meta:
model = StudentPayment
学生为特定的论文付费。我使用 ModelForms 生成一个表格来为学生添加论文或付款。创建 StudentPaymentForm 时,论文的选择字段包含已添加到数据库中的所有论文。有没有办法让论文选择字段仅包含特定选择的学生(来自学生选择字段)的论文,还是 jquery(或 ajax)任务?