本文整理匯總了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))