I have a departmental structure, where reports
belong to a subset of Departments
. In this case, a Department
can be a county
, and a report has an FK to a 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()
I would like Report.county
to use CountyDepartmentManager()
so only counties appear in the Report.county select field.
Is it even possible, or do I have to make these definitions in the Form
class?