如何使用django-filters应用过滤结果的条件 例如,我有一个字段说'Bookscount'具有整数值,如果用户选择值> 5,则django-filter将显示所有那些'Bookscount'> 5
的书。import django_filters as df
from .models import Books
class BooksListFilter(df.FilterSet):
class Meta:
model = Books
fields = ['Bookscount']
答案 0 :(得分:0)
您需要声明过滤器,或使用Meta.fields
class BooksListFilter(df.FilterSet):
min_books = df.NumberFilter(field_name='Bookscount', lookup_expr='gte')
# or
class BooksListFilter(df.FilterSet):
class Meta:
model = Books
fields = {'Bookscount': ['gt']}