Add video support with unified media display.
All checks were successful
Docker / build (release) Successful in 9s
All checks were successful
Docker / build (release) Successful in 9s
This commit is contained in:
parent
a634cc88bd
commit
f4052a3d99
16 changed files with 700 additions and 224 deletions
|
|
@ -5,7 +5,7 @@
|
|||
from django.contrib import admin
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from .models import Gallery, Photo, Tag
|
||||
from .models import Gallery, Photo, Tag, Video
|
||||
|
||||
|
||||
class GalleryAdmin(admin.ModelAdmin):
|
||||
|
|
@ -29,40 +29,31 @@ class GalleryAdmin(admin.ModelAdmin):
|
|||
|
||||
|
||||
|
||||
class PhotoAdmin(admin.ModelAdmin):
|
||||
list_display = (
|
||||
"title",
|
||||
"date_taken",
|
||||
"date_added",
|
||||
"is_public",
|
||||
"view_count",
|
||||
"admin_thumbnail",
|
||||
"get_owner",
|
||||
"get_galleries"
|
||||
)
|
||||
list_filter = ["date_added", "is_public", "owner","galleries"]
|
||||
class MediaAdmin(admin.ModelAdmin):
|
||||
"""Shared admin base for Photo and Video."""
|
||||
list_filter = ["date_added", "is_public", "owner", "galleries"]
|
||||
search_fields = ["title", "slug", "caption"]
|
||||
list_per_page = 25
|
||||
prepopulated_fields = {"slug": ("title",)}
|
||||
readonly_fields = ("date_taken",)
|
||||
model = Photo
|
||||
|
||||
def get_owner(self, obj):
|
||||
return obj.owner.username
|
||||
|
||||
|
||||
def get_queryset(self, request):
|
||||
# Précharge les objets 'galleries' en une seule requête supplémentaire
|
||||
return super().get_queryset(request).prefetch_related("owner",'galleries')
|
||||
|
||||
|
||||
def get_galleries(self, obj):
|
||||
return ", ".join([g.title for g in obj.galleries.all()])## get all linked galeries
|
||||
|
||||
get_galleries.short_description = _("Gallery")
|
||||
get_galleries.admin_order_field = 'galleries__title'
|
||||
return ", ".join([g.title for g in obj.galleries.all()])
|
||||
|
||||
def get_queryset(self, request):
|
||||
return super().get_queryset(request).prefetch_related("owner", "galleries")
|
||||
|
||||
get_owner.admin_order_field = "owner"
|
||||
get_owner.short_description = _("owner")
|
||||
get_galleries.short_description = _("Gallery")
|
||||
|
||||
|
||||
class PhotoAdmin(MediaAdmin):
|
||||
list_display = ("title", "date_taken", "date_added", "is_public", "view_count", "admin_thumbnail", "get_owner", "get_galleries")
|
||||
readonly_fields = ("date_taken",)
|
||||
model = Photo
|
||||
|
||||
|
||||
class TagAdmin(admin.ModelAdmin):
|
||||
|
|
@ -72,6 +63,12 @@ class TagAdmin(admin.ModelAdmin):
|
|||
model = Tag
|
||||
|
||||
|
||||
class VideoAdmin(MediaAdmin):
|
||||
list_display = ("title", "date_added", "is_public", "get_owner", "get_galleries")
|
||||
model = Video
|
||||
|
||||
|
||||
admin.site.register(Gallery, GalleryAdmin)
|
||||
admin.site.register(Photo, PhotoAdmin)
|
||||
admin.site.register(Video, VideoAdmin)
|
||||
admin.site.register(Tag, TagAdmin)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue