Make it possible to add a new platform
This commit is contained in:
parent
4c642d97cb
commit
bf61326c18
|
@ -2,3 +2,4 @@
|
|||
* Hide navigation bar items if there are no games/purchases/sessions
|
||||
* Set default version to "git-main" to indicate development environment
|
||||
* Add homepage, link to it from the logo
|
||||
* Make it possible to add a new platform
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from django import forms
|
||||
from .models import Session, Purchase, Game
|
||||
from .models import Session, Purchase, Game, Platform
|
||||
|
||||
|
||||
class SessionForm(forms.ModelForm):
|
||||
|
@ -24,3 +24,9 @@ class GameForm(forms.ModelForm):
|
|||
class Meta:
|
||||
model = Game
|
||||
fields = ["name", "wikidata"]
|
||||
|
||||
|
||||
class PlatformForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Platform
|
||||
fields = ["name", "group"]
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
<ul
|
||||
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_platform' %}">New Platform</a></li>
|
||||
{% 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>
|
||||
{% endif %}
|
||||
|
|
|
@ -5,6 +5,7 @@ from . import views
|
|||
urlpatterns = [
|
||||
path("", views.index, name="index"),
|
||||
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-purchase/", views.add_purchase, name="add_purchase"),
|
||||
path("list-sessions/", views.list_sessions, name="list_sessions"),
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from django.shortcuts import render
|
||||
|
||||
from .models import Game, Platform, Purchase, Session
|
||||
from .forms import SessionForm, PurchaseForm, GameForm
|
||||
from .forms import SessionForm, PurchaseForm, GameForm, PlatformForm
|
||||
from datetime import datetime
|
||||
def model_counts(request):
|
||||
return {
|
||||
|
@ -66,6 +66,18 @@ def add_game(request):
|
|||
context["title"] = "Add New Game"
|
||||
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):
|
||||
context = {}
|
||||
return render(request, "index.html", context)
|
||||
|
|
Loading…
Reference in New Issue