这是我的过滤器
class RiderFilter(django_filters.FilterSet):
cost_gt = django_filters.NumberFilter(label='Costo maggiore di',lookup_expr='cost__gt')
cost_lt = django_filters.NumberFilter(label='Costo minore di',lookup_expr='cost__lt')
class Meta:
model = Rider
fields = [ ]
如何为我的cost_gt和cost_lt添加一些特定的选择?
答案 0 :(得分:0)
您应该可以使用ChoiceFilter
。
class RiderFilter(django_filters.FilterSet):
cost_gt = django_filters.ChoiceFilter(
label='Costo maggiore di',
field_name='cost', lookup_expr='gt',
choices=[(1, '1'), (2, '2'), (3, '3')],
)
cost_lt = django_filters.NumberFilter(
label='Costo minore di',
field_name='cost', lookup_expr='lt',
choices=[(4, '4'), (5, '5'), (6, '6')],
)