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

398
Views
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 answers
Answer question

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