本文整理汇总了Python中django_filters.ChoiceFilter方法的典型用法代码示例。如果您正苦于以下问题:Python django_filters.ChoiceFilter方法的具体用法?Python django_filters.ChoiceFilter怎么用?Python django_filters.ChoiceFilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django_filters
的用法示例。
在下文中一共展示了django_filters.ChoiceFilter方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: filter_for_lookup
# 需要导入模块: import django_filters [as 别名]
# 或者: from django_filters import ChoiceFilter [as 别名]
def filter_for_lookup(cls, field, lookup_type):
filter_class, params = super().filter_for_lookup(field, lookup_type)
if filter_class == django_filters.ChoiceFilter:
params.setdefault('widget', ButtonSelect)
params.setdefault('empty_label', _("All"))
elif filter_class in [django_filters.DateFilter, django_filters.DateTimeFilter]:
params.setdefault('widget', AdminDateInput)
elif filter_class == django_filters.DateFromToRangeFilter:
params.setdefault('widget', DateRangePickerWidget)
elif filter_class == django_filters.BooleanFilter:
params.setdefault('widget', BooleanButtonSelect)
return filter_class, params
示例2: get_filterset_extra_class_attributes
# 需要导入模块: import django_filters [as 别名]
# 或者: from django_filters import ChoiceFilter [as 别名]
def get_filterset_extra_class_attributes(self):
ret = dict(
datemin=DateFilter(lookup_expr='gte', label='Date minimale'),
datemax=DateFilter(lookup_expr='lte', label='Date maximale'),
menu=django_filters.ChoiceFilter(
choices=EmailTemplate.MENU_CHOICES
)
)
if self.show_caisse_filter:
ret['caisse'] = type(
'CaissesFilter',
(NoopFilter, django_filters.ModelMultipleChoiceFilter),
dict()
)(
label='Caisses',
queryset=self.caisses
)
if self.show_user_filter:
qs = User.objects.filter(groups__name='UPN')
if self.request.user.profile != 'admin':
qs = qs.filter(caisses__in=self.caisses)
ret['user'] = type(
'UserFilter',
(NoopFilter, django_filters.ModelChoiceFilter),
dict()
)(
label='Utilisateur',
queryset=qs
)
return ret
示例3: __init__
# 需要导入模块: import django_filters [as 别名]
# 或者: from django_filters import ChoiceFilter [as 别名]
def __init__(self, *args, **kwargs):
super(DeviceFilter, self).__init__(*args, **kwargs)
# Add "Any" entry to choice fields.
for name, f in self.filters.items():
if isinstance(f, django_filters.ChoiceFilter):
f.field.choices = tuple([("", "Any"), ] + list(f.field.choices))