From a7dd0c5556008e74606d278e81d0aef507dae7c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Wed, 15 Nov 2023 14:25:42 +0100 Subject: [PATCH] Only allow choosing purchases of selected edition --- CHANGELOG.md | 1 + games/forms.py | 16 +++++++++++++++- games/templates/base.html | 2 +- games/templates/list_sessions.html | 1 - .../partials/related_purchase_field.html | 1 + games/urls.py | 5 +++++ games/views.py | 9 +++++++++ 7 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 games/templates/partials/related_purchase_field.html diff --git a/CHANGELOG.md b/CHANGELOG.md index 43b2d22..c98d5ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Improved * game overview: improve how editions and purchases are displayed +* add purchase: only allow choosing purchases of selected edition ## 1.5.1 / 2023-11-14 21:10+01:00 diff --git a/games/forms.py b/games/forms.py index 19af792..a5e4384 100644 --- a/games/forms.py +++ b/games/forms.py @@ -1,5 +1,5 @@ from django import forms - +from django.urls import reverse from games.models import Game, Platform, Purchase, Session, Edition, Device custom_date_widget = forms.DateInput(attrs={"type": "date"}) @@ -50,6 +50,20 @@ class IncludePlatformSelect(forms.Select): class PurchaseForm(forms.ModelForm): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + # Automatically update related_purchase