我正在使用此模型创建管理页面:
Model.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)