From 0e052f3db87ed0a61b2d5598521bc66b73c76f7c Mon Sep 17 00:00:00 2001 From: Matt Westcott Date: Thu, 1 Sep 2016 15:59:12 +0100 Subject: [PATCH] Optimise (and fix ordering of) submission queries --- wagtail/wagtailforms/edit_handlers.py | 6 ++++-- .../wagtailforms/edit_handlers/form_responses_panel.html | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/wagtail/wagtailforms/edit_handlers.py b/wagtail/wagtailforms/edit_handlers.py index fcd0de8dab..93c61531d7 100644 --- a/wagtail/wagtailforms/edit_handlers.py +++ b/wagtail/wagtailforms/edit_handlers.py @@ -13,13 +13,15 @@ class BaseFormSubmissionsPanel(EditHandler): def render(self): from .models import FormSubmission submissions = FormSubmission.objects.filter(page=self.instance) + submission_count = submissions.count() - if not submissions: + if not submission_count: return '' return mark_safe(render_to_string(self.template, { 'self': self, - 'submissions': submissions + 'submission_count': submission_count, + 'last_submit_time': submissions.order_by('submit_time').last().submit_time, })) diff --git a/wagtail/wagtailforms/templates/wagtailforms/edit_handlers/form_responses_panel.html b/wagtail/wagtailforms/templates/wagtailforms/edit_handlers/form_responses_panel.html index 340e4beef5..b8774cb40f 100644 --- a/wagtail/wagtailforms/templates/wagtailforms/edit_handlers/form_responses_panel.html +++ b/wagtail/wagtailforms/templates/wagtailforms/edit_handlers/form_responses_panel.html @@ -9,7 +9,7 @@
@@ -19,7 +19,7 @@

- {{ submissions.last.submit_time }} + {{ last_submit_time }}