diff --git a/src/character/models/character.py b/src/character/models/character.py index 78c790c..b45133e 100644 --- a/src/character/models/character.py +++ b/src/character/models/character.py @@ -3,6 +3,7 @@ from collections.abc import Iterable import markdown from django.db import models +from django.db.models import Q from django.db.models.functions import Lower from django.urls import reverse from django_extensions.db.models import TimeStampedModel @@ -75,7 +76,11 @@ class CharacterManager(models.Manager): class CharacterQuerySet(models.QuerySet): def managed_by(self, user): - return self.filter(player=user) + from party.models import Party + + return self.filter( + Q(player=user) | Q(parties__in=Party.objects.managed_by(user)) + ) def owned_by(self, user): return self.filter(player=user) diff --git a/src/party/models.py b/src/party/models.py index 7e5d5e9..ff072e2 100644 --- a/src/party/models.py +++ b/src/party/models.py @@ -1,4 +1,5 @@ from django.db import models +from django.db.models import Q from django_extensions.db.models import TimeStampedModel from character.models import Character @@ -12,6 +13,12 @@ class PartyQuerySet(models.QuerySet): def played_by(self, user): return self.filter(characters__in=Character.objects.filter(player=user)) + def related_to(self, user): + return self.filter( + Q(game_master=user) + | Q(characters__in=Character.objects.filter(player=user)) + ).distinct() + class PartyManager(UniquelyNamedModelManager): pass diff --git a/src/party/templates/party/party_details.html b/src/party/templates/party/party_details.html new file mode 100644 index 0000000..4dedd0e --- /dev/null +++ b/src/party/templates/party/party_details.html @@ -0,0 +1,21 @@ +{% extends "common/base.html" %} +{% load django_bootstrap5 %} +{% load character_extras %} + +{% block title %}{{ party.name }} · Groupe{% endblock %} + +{% block content %} +

{{ party.name }}

+

Personnages :

+ +{% endblock %} diff --git a/src/party/templates/party/snippets/party_card.html b/src/party/templates/party/snippets/party_card.html index fd5da46..5db2b25 100644 --- a/src/party/templates/party/snippets/party_card.html +++ b/src/party/templates/party/snippets/party_card.html @@ -4,7 +4,7 @@
{{ party.name }}
- + Accéder diff --git a/src/party/urls.py b/src/party/urls.py index 310cff0..ea0f735 100644 --- a/src/party/urls.py +++ b/src/party/urls.py @@ -6,4 +6,5 @@ app_name = "party" urlpatterns = [ path("", views.parties_list, name="list"), path("create/", views.party_create, name="create"), + path("/", views.party_details, name="details"), ] diff --git a/src/party/views.py b/src/party/views.py index 591646e..89dbd63 100644 --- a/src/party/views.py +++ b/src/party/views.py @@ -1,5 +1,5 @@ from django.contrib.auth.decorators import login_required -from django.shortcuts import redirect, render +from django.shortcuts import get_object_or_404, redirect, render from party.forms import PartyForm from party.models import Party @@ -28,3 +28,10 @@ def party_create(request): return redirect("party:list") context = {"form": form} return render(request, "party/party_create.html", context) + + +@login_required +def party_details(request, pk): + party = get_object_or_404(Party.objects.related_to(request.user), pk=pk) + context = {"party": party} + return render(request, "party/party_details.html", context)