Reusable ordered gallery primitives for Django projects.
Project description
django-gallery-core
Reusable Django primitives for ordered image galleries.
django-gallery-core is a small package for teams that want gallery behavior without pulling in a full CMS. It focuses on a narrow, stable API:
- an abstract ordered image model
- a migration-safe upload path helper
- a reusable DRF serializer base
- a reusable Django admin inline
- a service for syncing gallery uploads from multipart requests
Why this package exists
Many Django projects need the same gallery pattern:
- a parent model such as
Project,CaseStudy, orBlogPost - a related ordered list of images
- admin editing support
- simple serializer output for public APIs
- safe upload handling for create and update flows
This package extracts that repeated plumbing into a reusable core while keeping app-specific decisions in your own code.
Features
OrderedGalleryImage: abstract base model for ordered image rowsGalleryUploadTo: deconstructible upload helper compatible with Django migrationsbuild_gallery_upload_to(...): convenience factory for upload pathsOrderedGalleryImageSerializer: serializer base for public API outputOrderedGalleryInline: reusable Django admin inlinesync_gallery_uploads(...): service for adding and removing images during multipart form handling
Installation
pip install django-gallery-core
For local development:
pip install -e ".[test]"
Add the app to INSTALLED_APPS:
INSTALLED_APPS = [
# ...
'gallery',
]
Public API
The intended public surface area is:
gallery.models.OrderedGalleryImagegallery.models.GalleryUploadTogallery.models.build_gallery_upload_togallery.serializers.OrderedGalleryImageSerializergallery.admin.OrderedGalleryInlinegallery.services.sync_gallery_uploadsgallery.services.reorder_gallery
Anything outside this surface should be treated as internal and may change more freely.
Quick Start
1. Define a parent model and gallery image model
from django.db import models
from gallery.models import OrderedGalleryImage, build_gallery_upload_to
class Project(models.Model):
title = models.CharField(max_length=120)
class ProjectImage(OrderedGalleryImage):
project = models.ForeignKey(
Project,
on_delete=models.CASCADE,
related_name='gallery_images',
)
image = models.ImageField(upload_to=build_gallery_upload_to('projects/gallery'))
2. Expose gallery data in an API serializer
from rest_framework import serializers
from gallery.serializers import OrderedGalleryImageSerializer
from gallery.services import sync_gallery_uploads
from .models import Project, ProjectImage
class ProjectImageSerializer(OrderedGalleryImageSerializer):
class Meta:
model = ProjectImage
fields = ['id', 'image', 'order']
class ProjectWriteSerializer(serializers.ModelSerializer):
gallery = ProjectImageSerializer(source='gallery_images', many=True, read_only=True)
class Meta:
model = Project
fields = ['id', 'title', 'gallery']
def update(self, instance, validated_data):
request = self.context['request']
# IDs to delete come from the client (e.g. a hidden field listing removed images)
remove_ids = [int(x) for x in request.data.getlist('remove_gallery_ids') if x]
instance = super().update(instance, validated_data)
sync_gallery_uploads(
instance=instance,
related_name='gallery_images',
image_model=ProjectImage,
gallery_files=request.FILES.getlist('gallery_images'),
remove_ids=remove_ids,
)
return instance
3. Reuse the admin inline
from django.contrib import admin
from gallery.admin import OrderedGalleryInline
from .models import Project, ProjectImage
class ProjectImageInline(OrderedGalleryInline):
model = ProjectImage
@admin.register(Project)
class ProjectAdmin(admin.ModelAdmin):
inlines = [ProjectImageInline]
Example
A minimal integration example lives in example.py.
Design Goals
- Stay close to native Django and DRF patterns
- Keep the package small and readable
- Avoid forcing a full gallery domain model onto consuming apps
- Preserve migration safety for upload path helpers
- Support practical admin and API use cases first
Non-Goals
- full media management
- asset optimization pipelines
- frontend gallery UI
- polymorphic attachment systems
- complete CMS abstractions
Development
# Install all dev dependencies (tests + linting)
pip install -e ".[dev]"
# Run tests with coverage
pytest --cov=gallery --cov-report=term-missing
# Lint
ruff check .
Versioning
This package is in early-stage development and currently targets a 0.x release line. Expect additive improvements while the public API settles.
License
MIT. See LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_gallery_core-0.1.0.tar.gz.
File metadata
- Download URL: django_gallery_core-0.1.0.tar.gz
- Upload date:
- Size: 9.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
674ae9c82eb9aaba9777b416bd87ce39170b877da607c870f9477106e5051f68
|
|
| MD5 |
377a78107a3b13a99c0c124c74555877
|
|
| BLAKE2b-256 |
06f3a28d8b505e5723208ea658425d720ada07aebd00a06b04b3e5748ca8d5d4
|
Provenance
The following attestation bundles were made for django_gallery_core-0.1.0.tar.gz:
Publisher:
publish.yml on rkaya21/django-gallery-core
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_gallery_core-0.1.0.tar.gz -
Subject digest:
674ae9c82eb9aaba9777b416bd87ce39170b877da607c870f9477106e5051f68 - Sigstore transparency entry: 1246079989
- Sigstore integration time:
-
Permalink:
rkaya21/django-gallery-core@6503f80874a3e5dccf90dfc170325133de867a78 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/rkaya21
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6503f80874a3e5dccf90dfc170325133de867a78 -
Trigger Event:
push
-
Statement type:
File details
Details for the file django_gallery_core-0.1.0-py3-none-any.whl.
File metadata
- Download URL: django_gallery_core-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
336d96b7e07b53558f6ca2d34a9f4fe864b62c3904cd9615ba168c9a76e56aaa
|
|
| MD5 |
cffd22981ba3a779927787dc4a84a1fa
|
|
| BLAKE2b-256 |
e598d442e6990089665aaba8baf100379532de6ff3b7f56ae7dbeb98c9cac659
|
Provenance
The following attestation bundles were made for django_gallery_core-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on rkaya21/django-gallery-core
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_gallery_core-0.1.0-py3-none-any.whl -
Subject digest:
336d96b7e07b53558f6ca2d34a9f4fe864b62c3904cd9615ba168c9a76e56aaa - Sigstore transparency entry: 1246080014
- Sigstore integration time:
-
Permalink:
rkaya21/django-gallery-core@6503f80874a3e5dccf90dfc170325133de867a78 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/rkaya21
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6503f80874a3e5dccf90dfc170325133de867a78 -
Trigger Event:
push
-
Statement type: