Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

203
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda