[Fixed]-Query Django Wagtail Document Model

1๐Ÿ‘

โœ…

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 %}
๐Ÿ‘คCharles Smith

Leave a comment