我有一个部门结构,reports
属于Departments
. 在这种情况下, aDepartment
可以是 a county
,并且报告具有 a 的 FK county
。
class Report(models.Model):
user = models.ForeignKey(User)
value = models.IntegerField()
county = models.ForeignKey('Department')
class CountyDepartmentManager(models.Manager):
def get_queryset(self):
return super(CountyDepartmentManager, self).get_queryset().filter(county=True)
class Department(models.Model):
name = models.CharField(max_length=256)
county = models.BooleanField(default=0)
objects = models.Manager()
county_objects = CountyDepartmentManager()
我想Report.county
使用CountyDepartmentManager()
,所以只有县出现在 Report.county 选择字段中。
甚至有可能,还是我必须在Form
课堂上做出这些定义?