Add private profile

This commit is contained in:
Gabriel Augendre 2022-11-09 18:19:08 +01:00
parent 35205a9524
commit ee2caf8a2f
5 changed files with 37 additions and 2 deletions

View file

@ -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"]}),
(

View file

@ -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é",
),
),
]

View file

@ -1 +1 @@
0036_delete_party
0037_character_private

View file

@ -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:

View file

@ -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