1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
import django_tables2 as tables
from .models import Country, Person
class CountryTable(tables.Table):
name = tables.Column()
population = tables.Column()
tz = tables.Column(verbose_name="time zone")
visits = tables.Column()
summary = tables.Column(order_by=("name", "population"))
class Meta:
model = Country
class ThemedCountryTable(CountryTable):
class Meta:
attrs = {"class": "paleblue"}
class CheckboxTable(tables.Table):
select = tables.CheckBoxColumn(empty_values=(), footer="")
population = tables.Column(attrs={"cell": {"class": "population"}})
class Meta:
model = Country
template_name = "django_tables2/bootstrap.html"
fields = ("select", "name", "population")
class BootstrapTable(tables.Table):
class Meta:
model = Person
template_name = "django_tables2/bootstrap.html"
fields = ("id", "country", "country__continent__name")
linkify = ("country", "country__continent__name")
class BootstrapTablePinnedRows(BootstrapTable):
class Meta(BootstrapTable.Meta):
pinned_row_attrs = {"class": "info"}
def get_top_pinned_data(self):
return [
{
"name": "Most used country: ",
"country": Country.objects.filter(name="Cameroon").first(),
}
]
class Bootstrap4Table(tables.Table):
country = tables.Column(linkify=True)
continent = tables.Column(accessor="country__continent", linkify=True)
class Meta:
model = Person
template_name = "django_tables2/bootstrap4.html"
attrs = {"class": "table table-hover"}
exclude = ("friendly",)
class Bootstrap5Table(tables.Table):
country = tables.Column(linkify=True)
continent = tables.Column(accessor="country__continent", linkify=True)
class Meta:
model = Person
template_name = "django_tables2/bootstrap5.html"
exclude = ("friendly",)
class SemanticTable(tables.Table):
country = tables.RelatedLinkColumn()
class Meta:
model = Person
template_name = "django_tables2/semantic.html"
exclude = ("friendly",)
class PersonTable(tables.Table):
id = tables.Column(linkify=True)
country = tables.Column(linkify=True)
class Meta:
model = Person
template_name = "django_tables2/bootstrap.html"
|