Setup very basic character view

This commit is contained in:
Gabriel Augendre 2022-10-30 10:12:49 +01:00
parent a7fa40bcf8
commit 9e816d2281
6 changed files with 36 additions and 3 deletions

View file

@ -1,5 +1,6 @@
from django.db import models
from django.db.models.functions import Lower
from django.urls import reverse
from django_extensions.db.models import TimeStampedModel
from character.models.dice import Dice
@ -113,6 +114,9 @@ class Character(models.Model):
def natural_key(self):
return (self.name, self.player_id)
def get_absolute_url(self):
return reverse("character:view", kwargs={"pk": self.pk})
@property
def modifier_strength(self) -> int:
return modifier(self.value_strength)

View file

@ -0,0 +1,8 @@
{% extends "common/base.html" %}
{% block title %}{{ character.name }}{% endblock %}
{% block content %}
<h1>{{ character.name }}</h1>
<p><a href="{% url "admin:character_character_change" object_id=character.pk %}">Edit</a></p>
{% endblock %}

6
src/character/urls.py Normal file
View file

@ -0,0 +1,6 @@
from django.urls import path
from character import views
app_name = "character"
urlpatterns = [path("<int:pk>/", views.character_view, name="view")]

View file

@ -1 +1,13 @@
# Create your views here.
from django.contrib.auth.decorators import login_required
from django.core.handlers.wsgi import WSGIRequest
from django.http import HttpResponse
from django.shortcuts import get_object_or_404, render
from character.models import Character
@login_required
def character_view(request: WSGIRequest, pk: int) -> HttpResponse:
character = get_object_or_404(Character, pk=pk)
context = {"character": character}
return render(request, "character/view.html", context)

View file

@ -25,6 +25,7 @@ urlpatterns = [
path("logout/", logout, {"next_page": settings.LOGOUT_REDIRECT_URL}, name="logout"),
path("admin/", admin.site.urls),
path("", hello_world, name="hello_world"),
path("character/", include("character.urls", namespace="character")),
]
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

View file

@ -4,10 +4,12 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Character Sheet</title>
<title>{% block title %}Character Sheet{% endblock %}</title>
</head>
<body>
{% include "common/hello-random.html" %}
{% block content %}
{% include "common/hello-random.html" %}
{% endblock %}
<script src="{% static 'vendor/htmx-1.8.2.min.js' %}" defer></script>
{% django_htmx_script %}
{% if debug %}