0

I have list of Pages in Admin Panel Forms that look like on screenshot.
How can I add chronological sorting for this or some kind of ordering? I want that pages with new form submissions will appear at top of this list. enter image description here

2 Answers2

0

You can build a QuerySet for your model and set the ordering to your needs. Quoting from the documentation,

you must apply the ordering explicitly when constructing a QuerySet:

news_items = NewsItemPage.objects.live().order_by('-publication_date')

Assuming you have a FormIndex Page listing the Form model, you can update its context like this:

class FormIndexPage(Page):
    ...

    def get_context(self, request):
        context = super().get_context(request)
        context['form_entries'] = Form.objects.live().order_by('-your_date_field')
        return context

Then use that updated context in your template,

{% for entry in form_entries %}
    {{ entry.title }}
{% endfor %}
phyominh
  • 266
  • 1
  • 7
0

Use the filter_form_submissions_for_user hook: https://docs.wagtail.io/en/stable/reference/hooks.html#filter-form-submissions-for-user

# wagtail_hooks.py

# Sort submission form list by published time
@hooks.register('filter_form_submissions_for_user')
def submissions_filter(user, queryset):
    return queryset.order_by("-last_published_at")
Favo Yang
  • 194
  • 3
  • 13