diff --git a/guild/forms.py b/guild/forms.py index 04eec4f..105ac29 100644 --- a/guild/forms.py +++ b/guild/forms.py @@ -1,5 +1,6 @@ +from typing import Any from django import forms -from guild.models import PlaySession, Character, Reward +from guild.models import NPC, PlaySession, Character, Reward from django.utils.translation import gettext as _ @@ -11,14 +12,22 @@ class PlaySessionCharacterForm(forms.ModelMultipleChoiceField): return character.name +class PlaySessionNPCForm(forms.ModelMultipleChoiceField): + def label_from_instance(self, npc): + return npc.name + + class PlaySessionForm(forms.ModelForm): characters = PlaySessionCharacterForm( queryset=Character.objects.all(), widget=forms.CheckboxSelectMultiple ) + npcs = PlaySessionNPCForm( + queryset=NPC.objects.all(), widget=forms.CheckboxSelectMultiple, required=False + ) class Meta: model = PlaySession - fields = ["date", "characters", "summary"] + fields = ["date", "characters", "summary", "npcs"] # set date wideget to type="date" widgets = { "date": forms.DateInput(attrs={"type": "date"}), diff --git a/guild/migrations/0013_npc_playsession_npcs.py b/guild/migrations/0013_npc_playsession_npcs.py new file mode 100644 index 0000000..cf407e4 --- /dev/null +++ b/guild/migrations/0013_npc_playsession_npcs.py @@ -0,0 +1,54 @@ +# Generated by Django 4.2.1 on 2023-08-25 18:41 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("guild", "0012_alter_character_options_alter_character_picture"), + ] + + operations = [ + migrations.CreateModel( + name="NPC", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("name", models.CharField(max_length=255)), + ("description", models.TextField()), + ( + "picture", + models.ImageField( + blank=True, + null=True, + upload_to="uploads/", + verbose_name="NPC Picture", + ), + ), + ( + "created_at", + models.DateTimeField(auto_now_add=True, verbose_name="created at"), + ), + ( + "updated_at", + models.DateTimeField(auto_now=True, verbose_name="updated at"), + ), + ], + options={ + "verbose_name": "npc", + "verbose_name_plural": "npcs", + }, + ), + migrations.AddField( + model_name="playsession", + name="npcs", + field=models.ManyToManyField(to="guild.npc", verbose_name="npcs"), + ), + ] diff --git a/guild/migrations/0014_alter_playsession_npcs.py b/guild/migrations/0014_alter_playsession_npcs.py new file mode 100644 index 0000000..94bc21c --- /dev/null +++ b/guild/migrations/0014_alter_playsession_npcs.py @@ -0,0 +1,19 @@ +# Generated by Django 4.2.1 on 2023-08-25 18:52 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("guild", "0013_npc_playsession_npcs"), + ] + + operations = [ + migrations.AlterField( + model_name="playsession", + name="npcs", + field=models.ManyToManyField( + blank=True, to="guild.npc", verbose_name="npcs" + ), + ), + ] diff --git a/guild/models.py b/guild/models.py index c7248a9..10fc08a 100644 --- a/guild/models.py +++ b/guild/models.py @@ -116,6 +116,7 @@ class PlaySession(models.Model): "Adventure", verbose_name=_("adventure"), on_delete=models.CASCADE ) characters = models.ManyToManyField("Character", verbose_name=_("characters")) + npcs = models.ManyToManyField("NPC", verbose_name=_("npcs"), blank=True) summary = models.TextField() @@ -199,3 +200,25 @@ class Reward(models.Model): def get_absolute_url(self): return reverse("guild:reward_detail", kwargs={"pk": self.pk}) + + +class NPC(models.Model): + name = models.CharField(max_length=255) + description = models.TextField() + + picture = models.ImageField( + _("NPC Picture"), null=True, blank=True, upload_to="uploads/" + ) + + created_at = models.DateTimeField(_("created at"), auto_now_add=True) + updated_at = models.DateTimeField(_("updated at"), auto_now=True) + + class Meta: + verbose_name = _("npc") + verbose_name_plural = _("npcs") + + def __str__(self): + return self.name + + def get_absolute_url(self): + return reverse("guild:npc_detail", kwargs={"pk": self.pk}) diff --git a/guild/templates/guild/adventure_detail.html b/guild/templates/guild/adventure_detail.html index a336661..54d74ed 100644 --- a/guild/templates/guild/adventure_detail.html +++ b/guild/templates/guild/adventure_detail.html @@ -8,11 +8,13 @@
Are you sure you want to delete {{ character.name}}?
+ + +{% endblock content %} \ No newline at end of file diff --git a/guild/templates/guild/npc_detail.html b/guild/templates/guild/npc_detail.html new file mode 100644 index 0000000..4683f06 --- /dev/null +++ b/guild/templates/guild/npc_detail.html @@ -0,0 +1,52 @@ +{% extends 'base.html' %} + +{% load guild_extras %} + +{% block content %} + + + +{{npc.description|md|safe}}
+No appearance yet.
+{% else %} +{{playsession.summary|md|safe}}
+ +