我正在使用此模型创建管理页面:
模型.py:
class Company(models.Model):
name = models.CharField(max_length=50)
mail = models.EmailField(null=True, blank=True)
NIF = models.CharField(max_length=9, null=True, blank=True)
def __unicode__(self):
return self.name
class Office(models.Model):
company = models.ForeignKey(Company)
name = models.CharField(max_length=50, default='Main')
dir = models.CharField(max_length=50)
def __unicode__(self):
return self.name
class Employee(models.Model):
oficina = models.ForeignKey(Office)
name = models.CharField(max_length=50)
mail = models.EmailField(null=True, blank=True)
def __unicode__(self):
return self.name
class Report(models.Model):
employee = models.ForeignKey(Employee)
problem = models.CharField(max_length=100)
finished = models.BooleanField()
当我想创建一个新的 ReportForm 时遇到问题……员工很多!我想在管理页面中询问员工之前进行过滤
先问公司,指定公司时问办公室,指定办公室时选择员工。有可能做到这一点吗?
这是我的 Admin.py 现在:
class ReportForm(admin.ModelAdmin):
fieldsets = [
(None, {
'fields': ['employee', 'problem', 'finished']
}),
]
admin.site.register(Report, ReportForm)