Skip to main content

Extend Wagtail's Documents with image previews and metadata from FilePreviews

Project description

Extend Wagtail’s Documents with image previews and metadata from FilePreviews


Install with pip:

$ pip install wagtaildocs_previews


In your settings file, add wagtaildocs_previews to INSTALLED_APPS:

    # ...
    # ...

You’ll also need to set WAGTAILDOCS_DOCUMENT_MODEL.

WAGTAILDOCS_DOCUMENT_MODEL = 'wagtaildocs_previews.PreviewableDocument'

URL configuration

from wagtaildocs_previews import urls as wagtaildocs_urls

urlpatterns = [
    # ...
    url(r'^documents/', include(wagtaildocs_urls)),
    # ...


Since we’re extending via WAGTAILDOCS_DOCUMENT_MODEL you should be using get_document_model() to reference to correct Document model.

from wagtail.wagtailcore.models import Page
from wagtail.wagtaildocs.models import get_document_model
from wagtail.wagtaildocs.edit_handlers import DocumentChooserPanel

class BookPage(Page):
    book_file = models.ForeignKey(

    content_panels = Page.content_panels + [

In your template now you’ll be able to access the preview_data field.

{% extends "base.html" %}
{% load wagtailcore_tags %}

{% block body_class %}resource-page{% endblock %}

{% block content %}
    <h2>{{ page.book_file.title }}</h2>
    <img src="{{ page.book_file.preview_data.preview.url|default:'' }}" alt="">
{% endblock %}

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for wagtaildocs-previews, version 0.0.1
Filename, size File type Python version Upload date Hashes
Filename, size wagtaildocs_previews-0.0.1.tar.gz (9.4 kB) File type Source Python version None Upload date Hashes View
Filename, size wagtaildocs_previews-0.0.1-py2.py3-none-any.whl (12.8 kB) File type Wheel Python version py2.py3 Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page