【发布时间】:2018-03-29 13:35:54
【问题描述】:
这是我的看法:
class PersonalView(SingleTableMixin, FilterView):
model = Invoice
template_name = 'invProj/index.html'
table_class = InvoiceTable
filterset_class = InvoiceFilter
context_object_name = 'invoice'
ordering = ['invoice_due_date']
def get_table_data(self):
return Invoice.objects.filter(invoice_owner__username=self.request.user).order_by('i
nvoice_due_date')
现在,get_table_data 做了正确的事,发票根据用户进行过滤。但是,InvoiceFilter(django_filters.FilterSet) 则不起作用。但是,当我不覆盖 get_table_data 时,它确实有效。
现在,看起来正常并正常通过的过滤器只是不过滤。无论我输入哪个过滤字符串,它总是按照get_table_data显示数据。
我怎样才能得到这一切?我想定义我的 custum 表数据并且让我定义的过滤器对其进行处理。
【问题讨论】:
标签: django python-3.x django-class-based-views django-tables2 django-filters