Is it possible to "respect" django-tables2 template ?
spapas opened this issue · 2 comments
A django-tables2 package has the template_name option to choose the template used:
For example something like
class CPVTable(tables.Table):
class Meta:
model = models.CPV
fields = ("id", "code", "name", "name_en")
attrs = {"class": "table table-sm table-stripped"}
template_name = "cpv-table.html"
The problem is that when my table inherits from ColumnShiftTable
(instead of Table
) this attribute is completely ignored. Whould it be possible somehow to respect that parameter? I understand that it may not be possible because the template must follow a particular layout in order to be compatible with django-tables2-column-shifter.
Thank you
Why don't you override a shifter_template
attr from ColumnShiftTable?
This attribute finally override template_name
attr from origin Table class.
class ColumnShiftTable(tables.Table):
....
shifter_template = "django_tables2_column_shifter/table.html"
....
def __init__(self, *args, **kwargs):
....
if hasattr(self, "template_name"):
self.template_name = self.shifter_template
else:
self.template = self.shifter_template
....
You can create your own template for shifter and override shifter_template
attribute in ColumnShiftTable class.
Your custom template can also inherit from django-tables2-column-shifter.templates.tables
for example
Custom Templase:
{% extends "django_tables2_column_shifter/bootstrap4.html" %}
I'll try it thank you!