首页 > 解决方案 > 向 ModelChoiceFilter 添加 None 选项

问题描述

我的过滤器运行良好,但我希望选择“无”来查找商家组==无的交易。我在文档中找不到这个选项,这不可能吗?

class TransactionFilter(django_filters.FilterSet):

    merchant_group = django_filters.ModelChoiceFilter(field_name='merchant__merchant_group', empty_label="Merchant", queryset=MerchantGroup.objects.all().order_by('name'))

标签: django-filter

解决方案


推荐阅读