Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

201
Views
How do I have a functioning all button with a SimpleListFilter

I have a django admin that I am trying to change my default filter for. I have the filter displaying the data I want as default but my all button is not functioning correctly because I am returning a specific queryset when the value is None. Is there a way to have a functioning all button without changing the 'All' value?

class EmailFilter(admin.SimpleListFilter):
    title = _('email category')

    parameter_name = 'email_category'

    def lookups(self, request, model_admin):
        return (
            (10, _('Forwarded')),
            (8, _('Spam')),
        )

    def queryset(self, request, queryset):
        if self.value() is not None:
            return queryset.filter(email_category=self.value())
        return queryset

class myAdmin(VersionAdmin):
    list_filter = (EmailFilter)
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

class EmailFilter(admin.SimpleListFilter):
   title = _('email category')

   parameter_name = 'email_category'

   def lookups(self, request, model_admin):
       return (
           (None, _('Forwarded')),
           (8, _('Spam')),
           ('all', _('All')),
       )

   def queryset(self, request, queryset):
       if not self.value():
           return queryset.filter(email_category=10)  # forwarded if None which it will be by default
       elif self.value() == 'all':
           return queryset
       else:
           return queryset.filter(email_category=self.value())
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!