Python django_filters.ChoiceFilter() Examples
The following are 3
code examples of django_filters.ChoiceFilter().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django_filters
, or try the search function
.
Example #1
Source File: crudlfap.py From mrs with GNU Affero General Public License v3.0 | 7 votes |
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
Example #2
Source File: filters.py From wagtail with BSD 3-Clause "New" or "Revised" License | 6 votes |
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
Example #3
Source File: views.py From feedthefox with Mozilla Public License 2.0 | 5 votes |
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))