Update upload template
This commit is contained in:
parent
8015d96c7a
commit
b2ffd28e8e
3 changed files with 209 additions and 165 deletions
|
@ -75,11 +75,11 @@ class AlbumAdmin(admin.ModelAdmin):
|
|||
"""Add custom upload route to admin."""
|
||||
urls = super().get_urls()
|
||||
custom_urls = [
|
||||
path('<int:album_id>/upload/', self.admin_site.admin_view(self.upload_photos), name="gallery_album_upload"),
|
||||
path('<int:album_id>/upload/', self.admin_site.admin_view(self.photo_upload), name="gallery_album_upload"),
|
||||
]
|
||||
return custom_urls + urls
|
||||
|
||||
def upload_photos(self, request, album_id, *args, **kwargs):
|
||||
def photo_upload(self, request, album_id, *args, **kwargs):
|
||||
"""Handle photo upload via admin UI."""
|
||||
album = get_object_or_404(Album, id=album_id)
|
||||
if request.method == 'POST' and request.FILES:
|
||||
|
@ -91,7 +91,7 @@ class AlbumAdmin(admin.ModelAdmin):
|
|||
Photo.objects.create(album=album, photo=file)
|
||||
return JsonResponse({"message": "Photos uploaded successfully!"})
|
||||
|
||||
return render(request, 'admin/upload_photos.html', {'album': album})
|
||||
return render(request, 'admin/photo_upload.html', {'album': album})
|
||||
|
||||
def upload_link(self, obj):
|
||||
"""Show 'Upload Photos' button in album list."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue