diff --git a/TODO.md b/TODO.md index f120fd4..89a8767 100644 --- a/TODO.md +++ b/TODO.md @@ -1,8 +1,2 @@ - -- Bigger default summary input - Preview Markdown in summary input -- add player to charater in session list and edit/create - - {{charater}} ({{player}}) -- add list of npcs -- status of character - - alive, dead, retired, unknown \ No newline at end of file +- add list of npcs \ No newline at end of file diff --git a/guild/forms.py b/guild/forms.py index 41ad804..feb8b33 100644 --- a/guild/forms.py +++ b/guild/forms.py @@ -1,14 +1,25 @@ from django import forms -from guild.models import PlaySession +from guild.models import PlaySession, Character + + +class PlaySessionCharacterForm(forms.ModelMultipleChoiceField): + def label_from_instance(self, character): + if character.player: + return "{} ({})".format(character.name, character.player.name) + else: + return character.name class PlaySessionForm(forms.ModelForm): + characters = PlaySessionCharacterForm( + queryset=Character.objects.all(), widget=forms.CheckboxSelectMultiple + ) + class Meta: model = PlaySession fields = ["date", "characters", "summary"] # set date wideget to type="date" widgets = { "date": forms.DateInput(attrs={"type": "date"}), - "characters": forms.CheckboxSelectMultiple(), "summary": forms.Textarea(attrs={"rows": 32}), } diff --git a/guild/migrations/0003_character_status.py b/guild/migrations/0003_character_status.py new file mode 100644 index 0000000..9dcc987 --- /dev/null +++ b/guild/migrations/0003_character_status.py @@ -0,0 +1,26 @@ +# Generated by Django 4.2.1 on 2023-06-19 17:48 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("guild", "0002_resource_alter_player_name_resourceearned"), + ] + + operations = [ + migrations.AddField( + model_name="character", + name="status", + field=models.CharField( + choices=[ + ("ALIVE", "Alive"), + ("DEAD", "Dead"), + ("RETIRED", "Retired"), + ("UNKNOWN", "Unknown"), + ], + default="ALIVE", + max_length=16, + ), + ), + ] diff --git a/guild/models.py b/guild/models.py index 3907290..c1fc8c4 100644 --- a/guild/models.py +++ b/guild/models.py @@ -60,8 +60,17 @@ class Adventure(models.Model): class Character(models.Model): + class Status(models.TextChoices): + ALIVE = "ALIVE", _("Alive") + DEAD = "DEAD", _("Dead") + RETIRED = "RETIRED", _("Retired") + UNKNOWN = "UNKNOWN", _("Unknown") + name = models.CharField(max_length=255) description = models.TextField() + status = models.CharField( + max_length=16, choices=Status.choices, default=Status.ALIVE + ) player = models.ForeignKey( "Player", @@ -94,6 +103,7 @@ class PlaySession(models.Model): class Meta: verbose_name = _("playsession") verbose_name_plural = _("playsessions") + ordering = ["-date"] def __str__(self): return str(self.date) diff --git a/guild/templates/guild/adventure_detail.html b/guild/templates/guild/adventure_detail.html index bf746b9..6027039 100644 --- a/guild/templates/guild/adventure_detail.html +++ b/guild/templates/guild/adventure_detail.html @@ -6,7 +6,14 @@
- Played by: - - {{ character.player.name }} - -
-{{character.description|md|safe}}
+No sessions played.
+{% else %} +No dungeon masters found.
+{% else %} +