1
0
Fork 0
mirror of https://github.com/Findus23/RPGnotes.git synced 2024-09-19 15:43:45 +02:00

replace suptitle with first line of description

This commit is contained in:
Lukas Winkler 2024-08-08 00:00:30 +02:00
parent ada293d724
commit 6c2dc94f30
Signed by: lukas
GPG key ID: 54DE4D798D244853
6 changed files with 35 additions and 7 deletions

View file

@ -8,7 +8,7 @@ from users.models import TenantUser
class CharacterForm(ModelForm): class CharacterForm(ModelForm):
class Meta: class Meta:
model = Character model = Character
fields = ["name", "subtitle", "description_md", "aliases", "player", "faction", "location", fields = ["name", "description_md", "aliases", "player", "faction", "location",
"archived", "color", "token_image", "large_image"] "archived", "color", "token_image", "large_image"]
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):

View file

@ -0,0 +1,21 @@
# Generated by Django 5.0.8 on 2024-08-07 21:55
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
("characters", "0017_character_linked_objects_and_more"),
]
operations = [
migrations.RemoveField(
model_name="character",
name="subtitle",
),
migrations.RemoveField(
model_name="historicalcharacter",
name="subtitle",
),
]

View file

@ -25,7 +25,6 @@ class Character(NameSlugModel, DescriptionModel, AliasModel, HistoryModel):
models.CharField(_("Nickname"), max_length=100), models.CharField(_("Nickname"), max_length=100),
verbose_name=_("Aliases"), blank=True, null=True verbose_name=_("Aliases"), blank=True, null=True
) )
subtitle = models.CharField(_("Subtitle"), max_length=100, blank=True)
player = models.ForeignKey( player = models.ForeignKey(
AUTH_USER_MODEL, on_delete=models.PROTECT, blank=True, null=True, AUTH_USER_MODEL, on_delete=models.PROTECT, blank=True, null=True,
related_name="characters", verbose_name=_("Player"), related_name="characters", verbose_name=_("Player"),
@ -82,3 +81,13 @@ class Character(NameSlugModel, DescriptionModel, AliasModel, HistoryModel):
@property @property
def graphkey(self): def graphkey(self):
return f"cha{self.pk}" return f"cha{self.pk}"
@property
def subtitle(self) -> str | None:
lines = self.description_md.splitlines()
if len(lines) == 0:
return None
first_line = lines[0]
if len(first_line) > 100:
return first_line[:100] + ""
return first_line

View file

@ -38,7 +38,6 @@
{% trans %}Edit{% endtrans %} {% trans %}Edit{% endtrans %}
</a> </a>
</h1> </h1>
<p>{{ character.subtitle }}</p>
{% if character.aliases %} {% if character.aliases %}
<p>{% trans %}Also known as:{% endtrans %}</p> <p>{% trans %}Also known as:{% endtrans %}</p>
<ul> <ul>

View file

@ -17,7 +17,9 @@
href="{{ character.get_absolute_url() }}"> href="{{ character.get_absolute_url() }}">
{{ character.name }} {{ character.name }}
</a> </a>
<div>{{ character.subtitle }}</div> {% if character.subtitle %}
<div>{{ character.subtitle }}</div>
{% endif %}
</div> </div>
</div> </div>
</li> </li>

View file

@ -30,9 +30,6 @@ class JSONResponseMixin:
if isinstance(object, Location): if isinstance(object, Location):
if object.parent: if object.parent:
description_list.append(f"in {object.parent}") description_list.append(f"in {object.parent}")
elif isinstance(object, Character):
if object.subtitle:
description_list.append(object.subtitle)
elif isinstance(object, Loot): elif isinstance(object, Loot):
if object.owner: if object.owner:
description_list.append(object.owner.name) description_list.append(object.owner.name)