Python django_filters.ModelChoiceFilter() Examples

The following are 1 code examples of django_filters.ModelChoiceFilter(). 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 vote down vote up
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