From 5c3927c25d51e907a176203431be3b23cdcfd8ae Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Mon, 27 Feb 2023 22:23:24 +0000 Subject: all working, queries improved, date-ordered. --- core/views/logbooks.py | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) (limited to 'core/views/logbooks.py') diff --git a/core/views/logbooks.py b/core/views/logbooks.py index 37d6aa9..626153c 100644 --- a/core/views/logbooks.py +++ b/core/views/logbooks.py @@ -1,10 +1,10 @@ - +from django.db.models import Q from django.shortcuts import render from django.views.generic.list import ListView import troggle.settings as settings from troggle.core.models.logbooks import LogbookEntry, PersonLogEntry -from troggle.core.models.survex import SurvexBlock +from troggle.core.models.survex import SurvexBlock, SurvexFile from troggle.core.models.troggle import Expedition, Person from troggle.core.models.wallets import Wallet from troggle.core.utils import TROG @@ -212,22 +212,13 @@ def logbookentry(request, date, slug): if this_logbookentry: if len(this_logbookentry) > 1: + # BUG return render(request, "object_list.html", {"object_list": this_logbookentry}) else: - wallets = set() - allwallets = Wallet.objects.all() - refwallets = allwallets.filter(survexblock__date=date) - for r in refwallets: - wallets.add(r) - - # Note that w.year() only works for wallets which have a valid JSON file existing - # This is very slow with a big lag as w.date() is a computed field - # Noticably slow with WSL2 and NTFS filesystem, even with caching as walletdate. - jwallets = allwallets.filter(walletdate=date) - for j in jwallets: - wallets.add(j) - - svxothers = SurvexBlock.objects.filter(date=date) + # https://stackoverflow.com/questions/739776/how-do-i-do-an-or-filter-in-a-django-query + wallets = Wallet.objects.filter(Q(survexblock__date=date) | Q(walletdate=date)).distinct() + svxothers = SurvexFile.objects.filter(survexblock__date=date).distinct() + this_logbookentry = this_logbookentry[0] # This is the only page that uses next_.. and prev_.. # and it is calculated on the fly in the model -- cgit v1.2.3