From ee2caf8a2f4ba15d9804b6a3ce013a974b7826ea Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Wed, 9 Nov 2022 18:19:08 +0100 Subject: [PATCH] Add private profile --- src/character/admin.py | 2 +- .../migrations/0037_character_private.py | 23 +++++++++++++++++++ src/character/migrations/max_migration.txt | 2 +- src/character/models/character.py | 7 ++++++ src/party/forms.py | 5 ++++ 5 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 src/character/migrations/0037_character_private.py diff --git a/src/character/admin.py b/src/character/admin.py index fd451f5..bacab7d 100644 --- a/src/character/admin.py +++ b/src/character/admin.py @@ -119,7 +119,7 @@ class CharacterAdmin(admin.ModelAdmin): fieldsets = [ ( "Identité", - {"fields": ["name", "player", "profile", "level", "race"]}, + {"fields": ["name", "player", "profile", "level", "race", "private"]}, ), ("Apparence", {"fields": ["gender", "age", "height", "weight"]}), ( diff --git a/src/character/migrations/0037_character_private.py b/src/character/migrations/0037_character_private.py new file mode 100644 index 0000000..726fc25 --- /dev/null +++ b/src/character/migrations/0037_character_private.py @@ -0,0 +1,23 @@ +# Generated by Django 4.1.2 on 2022-11-09 17:13 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("character", "0036_delete_party"), + ] + + operations = [ + migrations.AddField( + model_name="character", + name="private", + field=models.BooleanField( + blank=True, + default=False, + help_text="Empêche toute invitation dans un groupe.", + verbose_name="privé", + ), + ), + ] diff --git a/src/character/migrations/max_migration.txt b/src/character/migrations/max_migration.txt index 208836e..db8ef09 100644 --- a/src/character/migrations/max_migration.txt +++ b/src/character/migrations/max_migration.txt @@ -1 +1 @@ -0036_delete_party +0037_character_private diff --git a/src/character/models/character.py b/src/character/models/character.py index 9892d14..90d65a9 100644 --- a/src/character/models/character.py +++ b/src/character/models/character.py @@ -202,6 +202,13 @@ class Character(models.Model): states = models.ManyToManyField(HarmfulState, blank=True, related_name="characters") + private = models.BooleanField( + "privé", + help_text="Empêche toute invitation dans un groupe.", + default=False, + blank=True, + ) + objects = CharacterManager.from_queryset(CharacterQuerySet)() class Meta: diff --git a/src/party/forms.py b/src/party/forms.py index 2d6d757..588bfce 100644 --- a/src/party/forms.py +++ b/src/party/forms.py @@ -1,6 +1,7 @@ from django import forms from django.core.exceptions import ValidationError +from character.models import Character from party.models import Party @@ -8,6 +9,10 @@ class PartyForm(forms.ModelForm): def __init__(self, *args, **kwargs): self.original_instance = kwargs.get("instance") super().__init__(*args, **kwargs) + qs = Character.objects.filter(private=False) + if self.original_instance: + qs = qs.union(self.original_instance.invited_characters.all()) + self.fields["invited_characters"].queryset = qs class Meta: model = Party