Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

178
Views
Query Django Wagtail Document Model

I have a client that has hundreds of documents that are tagged that we need to query and list on a page. I want to write a TemplateTag so its more reusable, but I have no idea how to query the builtin Wagtail image and document models. The below code is what I am starting with Document.objects.all() added for placement only. Any help would be appreciated.

@register.inclusion_tag(
    'tags/_document_snippets.html', takes_context=True
)
def document_snippets(context):
    documents = Documents.objects.all()
    return {
        'documents': documents,
        'request': context['request'],
    }
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

So I thought I would answer my own question for the benefit of others.

import get_document_model

from wagtail.wagtaildocs.models import get_document_model

create tag

@register.inclusion_tag(
    'tags/_documents_snippets.html',
    takes_context=True
)
def document_snippets(context):
    Document = get_document_model()
    documents = Document.objects.all()
    return {
        'documents': documents,
        'request': context['request'],
    }

add to template

{% for doc in documents %}
    <a href="{{ doc.url }}">{{ doc.title }}</a>
{% endfor %}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!