Gallery Page Model
TheGalleryPage model links to image collections:
base/models.py
Template Implementation
Gallery Page Template
The gallery page template uses a custom template tag to render images:base/gallery_page.html
Custom Template Tag
Thegallery template tag retrieves and displays images from a collection:
base/templatetags/gallery_tags.py
The gallery template tag uses an inclusion tag, which renders the
tags/gallery.html template with the filtered images.Image Collections
Create a Collection
Collections are created in the Wagtail admin at
/admin/collections/:- Navigate to Settings → Collections
- Click “Add a collection”
- Give it a descriptive name
- Set permissions if needed
Add Images to Collection
When uploading images in the admin:
- Go to Images section
- Upload new images or edit existing ones
- Select the appropriate collection from the dropdown
- Images can be moved between collections at any time
Image API Configuration
Images are exposed through the API with collection metadata:base/models.py
Why Add Collection to API Fields?
Why Add Collection to API Fields?
Adding the collection field to the Image API allows API consumers to:
- Filter images by collection
- Display collection information alongside images
- Build gallery interfaces in headless/decoupled architectures
- Organize images programmatically
Image Features
AVIF Quality Settings
The demo configures AVIF image quality for modern browsers:settings/base.py
Image Model Integration
Images are used throughout the demo with various features:Responsive Images
Wagtail automatically generates multiple image sizes for responsive display.
Image Renditions
Create custom image sizes using filters like
fill-800x600 or width-1200.Focal Points
Editors can set focal points to ensure important parts of images are preserved when cropped.
Multiple Formats
Wagtail serves images in modern formats (WebP, AVIF) with automatic fallbacks.
StreamField Image Blocks
Images can also be added to pages through StreamField blocks:base/blocks.py
Using in StreamField
base/blocks.py
Collection Permissions
Collections support granular permissions:- Add images: Control who can upload to specific collections
- Change images: Control who can edit images in collections
- Choose images: Control which collections are visible in image choosers
Collection permissions are particularly useful for:
- Multi-tenant sites where different departments manage their own images
- Client portals where clients should only access their own images
- Workflow separation between draft and published assets
Gallery Display Patterns
Grid Layout
The demo uses a grid layout for gallery display:Image Renditions
Generate thumbnails and optimized versions:Best Practices
Organize with Collections
Use collections to group related images by:
- Project or campaign
- Department or team
- Time period or season
- Content type or purpose
Use Focal Points
Encourage editors to set focal points for images that will be cropped in different contexts.
Advanced Features
Custom Image Models
Extend the base Image model for additional metadata:When to Use Custom Image Models
When to Use Custom Image Models
Consider a custom image model when you need to:
- Track copyright or licensing information
- Store photographer credits
- Add custom metadata fields
- Implement custom image processing workflows
- Integrate with external asset management systems

