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

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

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 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