mirror of
https://github.com/Crocmagnon/charasheet.git
synced 2024-12-22 13:51:49 +01:00
Setup very basic character view
This commit is contained in:
parent
a7fa40bcf8
commit
9e816d2281
6 changed files with 36 additions and 3 deletions
|
@ -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)
|
||||
|
|
8
src/character/templates/character/view.html
Normal file
8
src/character/templates/character/view.html
Normal 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
6
src/character/urls.py
Normal 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")]
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 %}
|
||||
|
|
Loading…
Reference in a new issue