Add group detail link and implement game removal functionality in views

This commit is contained in:
Edgar P. Burkhart 2025-06-13 23:16:53 +02:00
parent 122ae40570
commit dfe312d47d
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
4 changed files with 47 additions and 7 deletions

View file

@ -31,6 +31,13 @@
</a>
<nav>
<ul>
{% if object.group %}
<li>
<a href="{% url 'group_detail' pk=object.group.pk %}">
<i class="ri-group-2-fill"></i> {{ object.group.name }}
</a>
</li>
{% endif %}
{% if user.is_authenticated %}
<li>{{ user.username }}</li>
<li>

View file

@ -16,13 +16,28 @@
<h2>
<i class="ri-play-circle-fill"></i> Parties
</h2>
<ul>
{% for game in group.musikgame_set.all %}
<li>
<a href="{% url "game_detail" pk=game.pk %}">{{ game.date }}</a>
</li>
{% endfor %}
</ul>
<table class="striped">
<thead>
<th>Date</th>
<th>Joueurs</th>
<th>
<i class="ri-delete-bin-fill"></i>
</th>
</thead>
<tbody>
{% for game in group.musikgame_set.all %}
<tr>
<td>
<a href="{% url "game_detail" pk=game.pk %}">{{ game.date }}</a>
</td>
<td>{{ game.players.all|join:", " }}</td>
<td>
<a href="{% url "group_remove_game" pk=game.pk %}"><i class="ri-close-fill" alt="Supprimer"></i></a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
<h2>
<i class="ri-group-2-fill"></i> Membres

View file

@ -26,6 +26,11 @@ urlpatterns = [
views.GroupRemoveMusicView.as_view(),
name="group_remove_music",
),
path(
"group/remove_game/<int:pk>/",
views.GroupRemoveGameView.as_view(),
name="group_remove_game",
),
path(
"group/<int:pk>/start_game/", views.GameCreateView.as_view(), name="start_game"
),

View file

@ -96,6 +96,19 @@ class GroupRemoveMusicView(OwnerFilterMixin, SingleObjectMixin, View):
return redirect(group)
class GroupRemoveGameView(SingleObjectMixin, View):
model = models.MusikGame
def get_queryset(self):
return super().get_queryset().filter(group__owner=self.request.user)
def get(self, request, pk):
game = self.get_object()
group = game.group
game.delete()
return redirect(group)
class GameCreateView(LoginRequiredMixin, CreateView):
model = models.MusikGame
form_class = forms.MusikGameForm