Z
Z
zkweb2015-10-19 17:18:42
Django
zkweb, 2015-10-19 17:18:42

How to select multiple records in list_filter in model?

In the list_filter filter, you must select multiple entries for filtering. That is, select, for example, active users and display them for filtering

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita Shultais, 2015-10-19
@zkweb

Add multiple items to list_filter

class PersonAdmin(admin.ModelAdmin):
    list_filter = ('is_active', 'company')

Sample code for discussions in the comments
class EngineerTypeFilter(SimpleListFilter):
    title = u'инженеры'
    parameter_name = 'engineer'
    #engineer__id__exact

    def lookups(self, request, model_admin):
        return (
            (None, u"Активные"),
            ('rejected', u"Уволенные"),
        )

    def queryset(self, request, queryset):
       if self.value() is None:
            records = queryset.filter(is_active=True)
       else:
            records = queryset.filter(is_active=False)
       return records

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question