first views. WIP

This commit is contained in:
Niko Abeler 2023-06-10 21:33:06 +02:00
parent d2388c4d4c
commit 36e2ee216d
11 changed files with 104 additions and 9 deletions

View File

@ -4,7 +4,7 @@ from django.utils.translation import gettext as _
class Player(models.Model): class Player(models.Model):
name = models.CharField(max_length=255) name = models.CharField(max_length=255, unique=True)
class Meta: class Meta:
verbose_name = _("player") verbose_name = _("player")
@ -14,7 +14,7 @@ class Player(models.Model):
return self.name return self.name
def get_absolute_url(self): def get_absolute_url(self):
return reverse("player_detail", kwargs={"pk": self.pk}) return reverse("guild:player_detail", kwargs={"pk": self.pk})
class Resource(models.Model): class Resource(models.Model):
@ -29,7 +29,7 @@ class Resource(models.Model):
return self.name return self.name
def get_absolute_url(self): def get_absolute_url(self):
return reverse("resource_detail", kwargs={"pk": self.pk}) return reverse("guild:resource_detail", kwargs={"pk": self.pk})
class Adventure(models.Model): class Adventure(models.Model):
@ -47,7 +47,7 @@ class Adventure(models.Model):
return self.name return self.name
def get_absolute_url(self): def get_absolute_url(self):
return reverse("adventure_detail", kwargs={"pk": self.pk}) return reverse("guild:adventure_detail", kwargs={"pk": self.pk})
class Character(models.Model): class Character(models.Model):
@ -64,7 +64,7 @@ class Character(models.Model):
return self.name return self.name
def get_absolute_url(self): def get_absolute_url(self):
return reverse("character_detail", kwargs={"pk": self.pk}) return reverse("guild:character_detail", kwargs={"pk": self.pk})
class PlaySession(models.Model): class PlaySession(models.Model):
@ -82,7 +82,7 @@ class PlaySession(models.Model):
return self.name return self.name
def get_absolute_url(self): def get_absolute_url(self):
return reverse("playsession_detail", kwargs={"pk": self.pk}) return reverse("guild:playsession_detail", kwargs={"pk": self.pk})
class ResourceEarned(models.Model): class ResourceEarned(models.Model):
@ -99,4 +99,4 @@ class ResourceEarned(models.Model):
return self.name return self.name
def get_absolute_url(self): def get_absolute_url(self):
return reverse("resourceearned_detail", kwargs={"pk": self.pk}) return reverse("guild:resourceearned_detail", kwargs={"pk": self.pk})

View File

@ -0,0 +1,15 @@
{% extends 'base.html' %}
{% block content %}
<h1>Character: {{ character.name }}</h1>
<h2>
Played by:
<a href="{% url 'guild:player_detail' character.player.id %}">
{{ character.player.name }}
</a>
</h2>
<p>{{character.description}}</p>
{% endblock content %}

View File

@ -0,0 +1,9 @@
{% extends 'base.html' %}
{% block content %}
<form action="" method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Create Character">
</form>
{% endblock content %}

View File

@ -2,4 +2,9 @@
{% block content %} {% block content %}
<h1>Home</h1> <h1>Home</h1>
<a href="{% url 'guild:create_player' %}">Create New Player</a>
<a href="{% url 'guild:create_character' %}">Create New Character</a>
{% endblock content %} {% endblock content %}

View File

@ -0,0 +1,18 @@
{% extends 'base.html' %}
{% block content %}
<h1>Player: {{ player.name }}</h1>
<h2>Characters</h2>
{% if not player.character_set %}
<p>No characters found.</p>
{% else %}
<ul>
{% for character in player.character_set.all %}
<li><a href="{% url 'guild:character_detail' character.id %}">{{ character.name }}</a></li>
{% endfor %}
</ul>
{% endif %}
{% endblock content %}

View File

@ -0,0 +1,9 @@
{% extends 'base.html' %}
{% block content %}
<form action="" method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Create Player">
</form>
{% endblock content %}

View File

@ -1,6 +1,13 @@
from django.urls import path from django.urls import path
import guild.views as views import guild.views as views
import guild.views.player as player_views
import guild.views.character as character_views
urlpatterns = [ urlpatterns = [
path("", views.HomeView.as_view(), name="home"), path("", views.HomeView.as_view(), name="home"),
# path("players/", views.PlayerListView.as_view(), name="player_list"),
path("players/create/", player_views.CreatePlayerView.as_view(), name="create_player"),
path("players/<int:pk>/", player_views.PlayerDetailView.as_view(), name="player_detail"),
path("characters/create/", character_views.CreateCharacterView.as_view(), name="create_character"),
path("characters/<int:pk>/", character_views.CharacterDetailView.as_view(), name="character_detail"),
] ]

View File

@ -1,6 +1,10 @@
from django.views.generic import TemplateView from django.views.generic import TemplateView, ListView, DetailView
from django.views.generic.edit import CreateView
from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.auth.mixins import LoginRequiredMixin
from guild.models import Player
# Create your views here. # Create your views here.
class HomeView(LoginRequiredMixin, TemplateView): class HomeView(LoginRequiredMixin, TemplateView):
template_name = "guild/home.html" template_name = "guild/home.html"

14
guild/views/character.py Normal file
View File

@ -0,0 +1,14 @@
from django.views.generic import TemplateView, ListView, DetailView
from django.views.generic.edit import CreateView
from django.contrib.auth.mixins import LoginRequiredMixin
from guild.models import Character
class CreateCharacterView(LoginRequiredMixin, CreateView):
model = Character
fields = ["name", "description", "player"]
class CharacterDetailView(LoginRequiredMixin, DetailView):
model = Character

14
guild/views/player.py Normal file
View File

@ -0,0 +1,14 @@
from django.views.generic import TemplateView, ListView, DetailView
from django.views.generic.edit import CreateView
from django.contrib.auth.mixins import LoginRequiredMixin
from guild.models import Player
class CreatePlayerView(LoginRequiredMixin, CreateView):
model = Player
fields = ["name"]
class PlayerDetailView(LoginRequiredMixin, DetailView):
model = Player

View File

@ -20,5 +20,5 @@ from django.urls import include, path
urlpatterns = [ urlpatterns = [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path("accounts/", include("django.contrib.auth.urls")), path("accounts/", include("django.contrib.auth.urls")),
path("", include("guild.urls")), path("", include(("guild.urls", "guild"), namespace="guild")),
] ]