diff --git a/src/character/templates/character/snippets/characters_list/character_card.html b/src/character/templates/character/snippets/characters_list/character_card.html index 73df085..6ec21bd 100644 --- a/src/character/templates/character/snippets/characters_list/character_card.html +++ b/src/character/templates/character/snippets/characters_list/character_card.html @@ -29,12 +29,11 @@ Jouer {% else %} - Gérer {% endif %} - {% if party %} + {% if party and character in party.characters.all %} Quitter le groupe diff --git a/src/party/forms.py b/src/party/forms.py index 9970d96..134fd7a 100644 --- a/src/party/forms.py +++ b/src/party/forms.py @@ -1,4 +1,5 @@ from django import forms +from django.core.exceptions import ValidationError from party.models import Party @@ -6,4 +7,17 @@ from party.models import Party class PartyForm(forms.ModelForm): class Meta: model = Party - fields = ["name", "characters"] + fields = ["name", "invited_characters"] + + def clean_invited_characters(self): + invited = self.cleaned_data["invited_characters"] + if not self.instance: + return invited + members = self.instance.characters.all() + for character in invited: + if character in members: + self.add_error( + "invited_characters", + ValidationError(f"{character} is already a group member."), + ) + return invited diff --git a/src/party/migrations/0002_party_invited_characters.py b/src/party/migrations/0002_party_invited_characters.py new file mode 100644 index 0000000..cdd3b5b --- /dev/null +++ b/src/party/migrations/0002_party_invited_characters.py @@ -0,0 +1,24 @@ +# Generated by Django 4.1.2 on 2022-11-06 14:10 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("character", "0036_delete_party"), + ("party", "0001_initial"), + ] + + operations = [ + migrations.AddField( + model_name="party", + name="invited_characters", + field=models.ManyToManyField( + blank=True, + related_name="invites", + to="character.character", + verbose_name="personnages invités", + ), + ), + ] diff --git a/src/party/migrations/max_migration.txt b/src/party/migrations/max_migration.txt index cbab66d..9b5eb09 100644 --- a/src/party/migrations/max_migration.txt +++ b/src/party/migrations/max_migration.txt @@ -1 +1 @@ -0001_initial +0002_party_invited_characters diff --git a/src/party/models.py b/src/party/models.py index ff072e2..ce6b898 100644 --- a/src/party/models.py +++ b/src/party/models.py @@ -31,6 +31,12 @@ class Party(UniquelyNamedModel, TimeStampedModel, models.Model): related_name="parties", verbose_name="meneur de jeu", ) + invited_characters = models.ManyToManyField( + "character.Character", + blank=True, + related_name="invites", + verbose_name="personnages invités", + ) characters = models.ManyToManyField( "character.Character", blank=True, diff --git a/src/party/templates/party/party_details.html b/src/party/templates/party/party_details.html index f734681..8ea6dad 100644 --- a/src/party/templates/party/party_details.html +++ b/src/party/templates/party/party_details.html @@ -7,9 +7,22 @@ {% block content %}
MJ : {{ party.game_master.get_full_name|default:party.game_master.username }}
+Aucun...
{% endfor %}