Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

179
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda