Skip to content

Instantly share code, notes, and snippets.

View kristinriebe's full-sized avatar

Kristin Riebe kristinriebe

View GitHub Profile
@kristinriebe
kristinriebe / _wagtail-custom-document-urls.txt
Last active December 2, 2023 17:01
Wagtail - use a custom url (document slug) to serve documents via a custom serve_view
# I prefer to serve documents using a document slug (derived from the title of the document)
# instead of using the filename, especially since filenames can become quite ugly (appended random strings).
# E.g. a file named 'campus_map.pdf' with titel 'Campus Map' may be uploaded as 'campus_map_asRfsgt.pdf'
# by Wagtail and is then served as e.g. '/documents/24/campus_map_asRfsgt.pdf' (if WAGTAILDOCS_SERVE_METHOD = 'serve_view').
# However, it would look much nicer, if it was served as '/documents/24/campus_map/', which could
# also be a more persistent document url, i.e. it would not change if the document object was changed by
# replacing the file with a new version (e.g. 'campus_map_v2.pdf').
# I could also shorten the URL to '/documents/campus_map/', omitting the id. However, lookups by id are
# much faster and we would need to ensure that these urls are unique.
@kristinriebe
kristinriebe / models.py
Last active December 31, 2020 15:14
Wagtail modelcluster with modelchooser: Example for ModelChooserPanel with filter_name for limiting choices
from django.db import models
from modelcluster.fields import ParentalKey
from modelcluster.models import ClusterableModel
from wagtail.admin.edit_handlers import FieldPanel, MultiFieldPanel, InlinePanel
from wagtail.core.models import Orderable
from wagtail.search import index
from wagtailmodelchooser import register_filter
from wagtailmodelchooser.edit_handlers import ModelChooserPanel
"""