Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

202
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda