more linking of pages

This commit is contained in:
Niko Abeler 2023-06-19 20:01:33 +02:00
parent 64f2c74ea8
commit 3a6e3a02d3
8 changed files with 98 additions and 21 deletions

View File

@ -1,8 +1,2 @@
- Bigger default summary input
- Preview Markdown in summary input - Preview Markdown in summary input
- add player to charater in session list and edit/create
- {{charater}} ({{player}})
- add list of npcs - add list of npcs
- status of character
- alive, dead, retired, unknown

View File

@ -1,14 +1,25 @@
from django import forms 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): class PlaySessionForm(forms.ModelForm):
characters = PlaySessionCharacterForm(
queryset=Character.objects.all(), widget=forms.CheckboxSelectMultiple
)
class Meta: class Meta:
model = PlaySession model = PlaySession
fields = ["date", "characters", "summary"] fields = ["date", "characters", "summary"]
# set date wideget to type="date" # set date wideget to type="date"
widgets = { widgets = {
"date": forms.DateInput(attrs={"type": "date"}), "date": forms.DateInput(attrs={"type": "date"}),
"characters": forms.CheckboxSelectMultiple(),
"summary": forms.Textarea(attrs={"rows": 32}), "summary": forms.Textarea(attrs={"rows": 32}),
} }

View File

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

View File

@ -60,8 +60,17 @@ class Adventure(models.Model):
class Character(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) name = models.CharField(max_length=255)
description = models.TextField() description = models.TextField()
status = models.CharField(
max_length=16, choices=Status.choices, default=Status.ALIVE
)
player = models.ForeignKey( player = models.ForeignKey(
"Player", "Player",
@ -94,6 +103,7 @@ class PlaySession(models.Model):
class Meta: class Meta:
verbose_name = _("playsession") verbose_name = _("playsession")
verbose_name_plural = _("playsessions") verbose_name_plural = _("playsessions")
ordering = ["-date"]
def __str__(self): def __str__(self):
return str(self.date) return str(self.date)

View File

@ -6,7 +6,14 @@
<div class="row"> <div class="row">
<div class="column column-75"> <div class="column column-75">
<hrgroup>
<h1>Adventure: {{ adventure.name }}</h1> <h1>Adventure: {{ adventure.name }}</h1>
<h4>Mastered by:
<a href="{% url 'guild:player_detail' adventure.master.id %}">
{{ adventure.master }}
</a>
</h4>
</hrgroup>
</div> </div>
<div class="column"> <div class="column">
<a class="button button-outline" href="{% url 'guild:adventure_update' adventure.id %}">Edit</a> <a class="button button-outline" href="{% url 'guild:adventure_update' adventure.id %}">Edit</a>

View File

@ -6,7 +6,16 @@
<div class="row"> <div class="row">
<div class="column column-75"> <div class="column column-75">
<hrgroup>
<h1>Character: {{ character.name }}</h1> <h1>Character: {{ character.name }}</h1>
<h4>
{{ character.get_status_display }}
, played by:
<a href="{% url 'guild:player_detail' character.player.id %}">
{{ character.player.name }}
</a>
</h4>
</hrgroup>
</div> </div>
<div class="column"> <div class="column">
<a class="button button-outline" href="{% url 'guild:character_update' character.id %}">Edit</a> <a class="button button-outline" href="{% url 'guild:character_update' character.id %}">Edit</a>
@ -16,13 +25,21 @@
</div> </div>
</div> </div>
<p>
Played by:
<a href="{% url 'guild:player_detail' character.player.id %}">
{{ character.player.name }}
</a>
</p>
<p>{{character.description|md|safe}}</p> <p>{{character.description|md|safe}}</p>
<h2>Session History</h2>
{% if not character.playsession_set.count %}
<p>No sessions played.</p>
{% else %}
<ul>
{% for session in character.playsession_set.all %}
<li>
<a href="{% url 'guild:adventure_detail' session.adventure.id %}">
{{session.date}} - {{ session.adventure.name }}
</a></li>
{% endfor %}
</ul>
{% endif %}
{% endblock content %} {% endblock content %}

View File

@ -20,7 +20,19 @@
{% else %} {% else %}
<ul> <ul>
{% for character in player.character_set.all %} {% for character in player.character_set.all %}
<li><a href="{% url 'guild:character_detail' character.id %}">{{ character.name }}</a></li> <li><a href="{% url 'guild:character_detail' character.id %}">{{ character.name }} ({{character.get_status_display}})</a></li>
{% endfor %}
</ul>
{% endif %}
<h2>Game Master Adventures</h2>
{% if not player.adventure_set.count %}
<p>No dungeon masters found.</p>
{% else %}
<ul>
{% for adventure in player.adventure_set.all %}
<li><a href="{% url 'guild:adventure_detail' adventure.id %}">{{ adventure.name }}</a></li>
{% endfor %} {% endfor %}
</ul> </ul>
{% endif %} {% endif %}

View File

@ -12,7 +12,7 @@ class CharacterListView(LoginRequiredMixin, ListView):
class CreateCharacterView(LoginRequiredMixin, CreateView): class CreateCharacterView(LoginRequiredMixin, CreateView):
model = Character model = Character
fields = ["name", "description", "player"] fields = ["name", "description", "player", "status"]
class CharacterDetailView(LoginRequiredMixin, DetailView): class CharacterDetailView(LoginRequiredMixin, DetailView):
@ -21,7 +21,7 @@ class CharacterDetailView(LoginRequiredMixin, DetailView):
class CharacterUpdateView(LoginRequiredMixin, UpdateView): class CharacterUpdateView(LoginRequiredMixin, UpdateView):
model = Character model = Character
fields = ["name", "description", "player"] fields = ["name", "description", "player", "status"]
class CharacterDeleteView(LoginRequiredMixin, DeleteView): class CharacterDeleteView(LoginRequiredMixin, DeleteView):