|
4 | 4 |
|
5 | 5 | from django.contrib import messages
|
6 | 6 | from django.contrib.auth.mixins import LoginRequiredMixin
|
| 7 | +from django.db.models import Q |
7 | 8 | from django.forms.models import BaseModelForm
|
8 | 9 | from django.http import Http404, HttpResponse, HttpResponseNotAllowed, JsonResponse
|
9 | 10 | from django.shortcuts import get_object_or_404, redirect, render
|
|
12 | 13 | from django.views.generic.detail import DetailView
|
13 | 14 | from django.views.generic.edit import UpdateView
|
14 | 15 | from django.views.generic.list import ListView
|
15 |
| -from django.db.models import Q |
16 |
| -from django.shortcuts import get_object_or_404 |
17 | 16 |
|
18 | 17 | # we need to import these to make sure the apps are registered
|
19 | 18 | import b4mad_racing_website.fastlap_app # noqa: F401
|
@@ -275,15 +274,17 @@ def sessions(request, template_name="sessions.html", **kwargs):
|
275 | 274 |
|
276 | 275 | sessions = []
|
277 | 276 | filter = {}
|
| 277 | + |
| 278 | + # Check existence and 404 if not found |
278 | 279 | if game_id:
|
| 280 | + context["game"] = get_object_or_404(Game, pk=game_id) |
279 | 281 | filter["game_id"] = game_id
|
280 |
| - context["game"] = Game.objects.get(pk=game_id) |
281 | 282 | if car_id:
|
| 283 | + context["car"] = get_object_or_404(Car, pk=car_id) |
282 | 284 | filter["laps__car_id"] = car_id
|
283 |
| - context["car"] = Car.objects.get(pk=car_id) |
284 | 285 | if track_id:
|
| 286 | + context["track"] = get_object_or_404(Track, pk=track_id) |
285 | 287 | filter["laps__track_id"] = track_id
|
286 |
| - context["track"] = Track.objects.get(pk=track_id) |
287 | 288 |
|
288 | 289 | # Calculate the start date based on the range
|
289 | 290 | start_date = datetime.now() - timedelta(days=365)
|
|
0 commit comments