Add more info to character view

This commit is contained in:
Gabriel Augendre 2022-10-30 10:54:28 +01:00
parent fe5a5c53f6
commit 07d9e4b660
3 changed files with 19 additions and 2 deletions

View file

@ -179,3 +179,11 @@ class Character(models.Model):
@property
def mana_remaining(self) -> int:
return self.mana_max - self.mana_consumed
@property
def height_m(self) -> float:
return round(self.height / 100, 2)
@property
def imc(self) -> float:
return self.weight / (self.height_m**2)

View file

@ -4,5 +4,14 @@
{% block content %}
<h1>{{ character.name }}</h1>
<p><a href="{% url "admin:character_character_change" object_id=character.pk %}">Edit</a></p>
<p>
<a href="{% url "admin:character_character_change" object_id=character.pk %}">Edit</a>
</p>
<p>
Joueur : {{ character.player.get_full_name|default:character.player.username }}
</p>
<p>
{{ character.race.name }} {{ character.profile.name }} niv. {{ character.level }}<br>
{{ character.get_gender_display }}, {{ character.age }} ans, {{ character.height_m }}m, {{ character.weight }}kg (IMC: {{ character.imc }})
</p>
{% endblock %}

View file

@ -8,6 +8,6 @@ from character.models import Character
@login_required
def character_view(request: WSGIRequest, pk: int) -> HttpResponse:
character = get_object_or_404(Character, pk=pk)
character = get_object_or_404(Character.objects.select_related("player"), pk=pk)
context = {"character": character}
return render(request, "character/view.html", context)