Make it possible to add a new platform

This commit is contained in:
Lukáš Kucharczyk 2023-01-04 17:23:34 +01:00
parent 4c642d97cb
commit bf61326c18
Signed by: lukas
SSH Key Fingerprint: SHA256:vMuSwvwAvcT6htVAioMP7rzzwMQNi3roESyhv+nAxeg
5 changed files with 23 additions and 2 deletions

View File

@ -2,3 +2,4 @@
* Hide navigation bar items if there are no games/purchases/sessions * Hide navigation bar items if there are no games/purchases/sessions
* Set default version to "git-main" to indicate development environment * Set default version to "git-main" to indicate development environment
* Add homepage, link to it from the logo * Add homepage, link to it from the logo
* Make it possible to add a new platform

View File

@ -1,5 +1,5 @@
from django import forms from django import forms
from .models import Session, Purchase, Game from .models import Session, Purchase, Game, Platform
class SessionForm(forms.ModelForm): class SessionForm(forms.ModelForm):
@ -24,3 +24,9 @@ class GameForm(forms.ModelForm):
class Meta: class Meta:
model = Game model = Game
fields = ["name", "wikidata"] fields = ["name", "wikidata"]
class PlatformForm(forms.ModelForm):
class Meta:
model = Platform
fields = ["name", "group"]

View File

@ -23,6 +23,7 @@
<ul <ul
class="flex flex-col md:flex-row p-4 mt-4 dark:text-white"> class="flex flex-col md:flex-row p-4 mt-4 dark:text-white">
<li><a class="block py-2 pl-3 pr-4 hover:underline" href="{% url 'add_game' %}">New Game</a></li> <li><a class="block py-2 pl-3 pr-4 hover:underline" href="{% url 'add_game' %}">New Game</a></li>
<li><a class="block py-2 pl-3 pr-4 hover:underline" href="{% url 'add_platform' %}">New Platform</a></li>
{% if game_available and platform_available %} {% if game_available and platform_available %}
<li><a class="block py-2 pl-3 pr-4 hover:underline" href="{% url 'add_purchase' %}">New Purchase</a></li> <li><a class="block py-2 pl-3 pr-4 hover:underline" href="{% url 'add_purchase' %}">New Purchase</a></li>
{% endif %} {% endif %}

View File

@ -5,6 +5,7 @@ from . import views
urlpatterns = [ urlpatterns = [
path("", views.index, name="index"), path("", views.index, name="index"),
path("add-game/", views.add_game, name="add_game"), path("add-game/", views.add_game, name="add_game"),
path("add-platform/", views.add_platform, name="add_platform"),
path("add-session/", views.add_session, name="add_session"), path("add-session/", views.add_session, name="add_session"),
path("add-purchase/", views.add_purchase, name="add_purchase"), path("add-purchase/", views.add_purchase, name="add_purchase"),
path("list-sessions/", views.list_sessions, name="list_sessions"), path("list-sessions/", views.list_sessions, name="list_sessions"),

View File

@ -1,7 +1,7 @@
from django.shortcuts import render from django.shortcuts import render
from .models import Game, Platform, Purchase, Session from .models import Game, Platform, Purchase, Session
from .forms import SessionForm, PurchaseForm, GameForm from .forms import SessionForm, PurchaseForm, GameForm, PlatformForm
from datetime import datetime from datetime import datetime
def model_counts(request): def model_counts(request):
return { return {
@ -66,6 +66,18 @@ def add_game(request):
context["title"] = "Add New Game" context["title"] = "Add New Game"
return render(request, "add.html", context) return render(request, "add.html", context)
def add_platform(request):
context = {}
form = PlatformForm(request.POST or None)
if form.is_valid():
form.save()
context["form"] = form
context["title"] = "Add New Platform"
return render(request, "add.html", context)
def index(request): def index(request):
context = {} context = {}
return render(request, "index.html", context) return render(request, "index.html", context)