我的models.py
中有以下内容class Department(models.Model):
department_id = models.AutoField(primary_key=True)
department_name = models.CharField(max_length=20,unique=True)
class Major(models.Model):
major_id = models.AutoField(primary_key=True)
major_name = models.CharField(max_length=20unique=True)
department_id = models.ForeignKey(Department)
class Student(models.Model):
...
department = models.ForeignKey(Department)
major = models.ForeignKey(Major)
现在在管理网站,我想创建一个学生,当我选择了部门时,我怎么能限制主要选择? 我尝试使用ModelAdmin.formfield_for_foreignkey,但我不知道如何转移param部门。那么,怎么做呢?