1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2025-07-18 15:20:19 +02:00

Better list tables

This commit is contained in:
Ehouarn
2025-07-17 20:07:12 +02:00
parent 249b797d5a
commit ab9abc8520
3 changed files with 26 additions and 10 deletions

View File

@ -3,6 +3,7 @@
import django_tables2 as tables
from django_tables2 import A
from django.urls import reverse
from .models import Family, Challenge, FamilyMembership
@ -11,11 +12,6 @@ class FamilyTable(tables.Table):
"""
List all families
"""
name = tables.LinkColumn(
"family:family_detail",
args=[A("pk")],
)
class Meta:
attrs = {
'class': 'table table-condensed table-striped table-hover'
@ -24,17 +20,17 @@ class FamilyTable(tables.Table):
template_name = 'django_tables2/bootstrap4.html'
fields = ('name', 'score', 'rank',)
order_by = ('rank',)
row_attrs = {
'class': 'table-row',
'data-href': lambda record: reverse('family:family_detail', args=[record.pk]),
'style': 'cursor:pointer',
}
class ChallengeTable(tables.Table):
"""
List all challenges
"""
name = tables.LinkColumn(
"family:challenge_detail",
args=[A("pk")],
)
class Meta:
attrs = {
'class': 'table table-condensed table-striped table-hover'
@ -43,6 +39,11 @@ class ChallengeTable(tables.Table):
model = Challenge
template_name = 'django_tables2/bootstrap4.html'
fields = ('name', 'description', 'points',)
row_attrs = {
'class': 'table-row',
'data-href': lambda record: reverse('family:challenge_detail', args=[record.pk]),
'style': 'cursor:pointer',
}
class FamilyMembershipTable(tables.Table):

View File

@ -28,3 +28,10 @@ SPDX-License-Identifier: GPL-3.0-or-later
</div>
{% endblock %}
{% block extrajavascript %}
<script type="text/javascript">
$(".table-row").click(function () {
window.document.location = $(this).data("href");
});
</script>
{% endblock %}

View File

@ -26,5 +26,13 @@ SPDX-License-Identifier: GPL-3.0-or-later
</h3>
{% render_table table %}
</div>
{% endblock %}
{% block extrajavascript %}
<script type="text/javascript">
$(".table-row").click(function () {
window.document.location = $(this).data("href");
});
</script>
{% endblock %}