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

397
Visualizações
django-tables2 exclude & field not working

I'm new to django and stumbling through creating my first site. I'm using django-tables2 to display a table and it appears to be working (the table shows up, it's sortable).

Except I can't seem to customize anything. Exclude, field and sequence don't work. Can't change column verbose names.

TABLE:

import django_tables2 as tables
from sl_overview.models import DailyslSumm

class slsummTable(tables.Table):

    class Meta:
        model = DailyslSumm
        exclude = ('index')

VIEW:

class sl_summ(SingleTableView):

    model = DailyslSumm
    context_object_name = 'slsummdb'
    table_class = slsummTable

TEMPLATE:

{% load render_table from django_tables2 %}
{% render_table slsummdb %}

The exclude in the code above doesn't work. The column is still there. Using field doesn't adjust columns either. I'm sure I'm missing something simple, thanks for any help.

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You must make sure exclude is a tuple (or list), and not a string. If you use parenthesis with one string, the resulting value will be a string, not a tuple like you might expect:

Python 3.5.2 (default, Nov 17 2016, 17:05:23) 
>>> ('foo')
'foo'
>>> ('foo', )
('foo',)
>>> 

In your case, you should add a comma after 'index' like this:

class slsummTable(tables.Table):

    class Meta:
        model = DailyslSumm
        exclude = ('index', )  # <- note the extra comma here
about 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