Это мои файлы models.py и admin.py, где я должен был сделать фильтр с 'reportbranch' и date_hierarchy с 'reportdate'. но выдает следующие ошибки:
ERRORS:
<class 'reports.admin.ReportSummaryAdmin'>: (admin.E116) The value of 'list_filter[1]' refers to 'reportbranch', which does not refer to a Field.
<class 'reports.admin.ReportSummaryAdmin'>: (admin.E127) The value of 'date_hierarchy' refers to 'reportdate', which does not refer to a Field.
models.py
class DailyReport(models.Model):
report_type = models.CharField(max_length=500, choices=REPORT_TYPE, verbose_name="Type")
date = models.DateField(verbose_name="Date")
branch = models.ForeignKey(Branch, on_delete=models.CASCADE, verbose_name="Branch")
added_by = models.ForeignKey(User, editable=False, on_delete=models.CASCADE, null=True, blank=True)
added_at = models.DateTimeField(auto_now=True, editable=False)
def __str__(self):
return str(self.date) + ' - ' +self.branch.name
class ReportItem(models.Model):
particular = models.ForeignKey(Particular, on_delete=models.CASCADE, verbose_name="Particular")
Report = models.ForeignKey(DailyReport, on_delete=models.CASCADE)
total_amount = models.DecimalField(max_digits=10, decimal_places=2, verbose_name="Total Amount")
quantity = models.IntegerField(verbose_name="Quantity")
remarks = models.CharField(max_length=5000, verbose_name="Remarks", null=True, blank=True)
class ReportSummary(ReportItem):
class Meta:
proxy = True
verbose_name = "Daily Report Summary"
verbose_name_plural = "Daily Report Summaries"
def reportdate(self):
return self.Report.date
def reportbranch(self):
return self.Report.branch.name
admin.py
class ReportSummaryAdmin(admin.ModelAdmin):
list_display = ['reportbranch','reportdate','particular','Report','total_amount','quantity']
list_filter = ['particular','reportbranch']
date_hierarchy = 'reportdate'
Почему возникает такая проблема, нужно ли мне что-то определять с помощью функции init ? Я запутался из-за причины этой проблемы и ее решения.