Skip to content

Add direct Cloudinary image upload to Django admin#429

Merged
rasca merged 2 commits intodevfrom
main
Mar 17, 2026
Merged

Add direct Cloudinary image upload to Django admin#429
rasca merged 2 commits intodevfrom
main

Conversation

@rasca
Copy link
Contributor

@rasca rasca commented Mar 17, 2026

Summary

  • Admin users can now upload images directly from the FeaturedContent change form instead of manually uploading to Cloudinary and pasting URLs
  • Reusable CloudinaryUploadMixin and CloudinaryUploadWidget can be applied to any future admin model with Cloudinary image fields
  • Image preview, file upload, manual URL fallback, and clear/delete functionality all in one widget

Changes

  • New backend/utils/admin_widgets.pyCloudinaryUploadWidget with multipart support, thumbnail preview, file input, URL input, and clear checkbox
  • New backend/utils/admin_mixins.pyCloudinaryUploadMixin that injects upload widgets, hides public_id fields, and handles upload/clear/delete on save
  • New backend/templates/admin/widgets/cloudinary_upload.html — Widget template
  • Modified backend/users/cloudinary_service.py — Added generic upload_image() method
  • Modified backend/contributions/admin.py — Applied mixin to FeaturedContentAdmin with 4 image field pairs

Test plan

  • Open FeaturedContent add/change form in admin
  • Verify file upload inputs appear next to each image URL field
  • Upload an image → confirm Cloudinary URL and public_id are auto-populated
  • Verify image preview shows after save
  • Replace an image → verify old image deleted from Cloudinary
  • Paste a manual URL (skip upload) → verify it saves correctly
  • Clear an image via checkbox → verify fields emptied and Cloudinary image deleted

rasca added 2 commits March 17, 2026 16:02
The FeaturedContent admin now supports uploading images directly from
the change form instead of requiring manual Cloudinary uploads and URL
pasting. A reusable CloudinaryUploadWidget renders a file input, image
preview, and URL fallback for each image field. On save, the
CloudinaryUploadMixin intercepts uploaded files, sends them to
Cloudinary via a new generic upload method, and auto-populates both the
URL and public_id fields. Old images are deleted from Cloudinary when
replaced, and a clear checkbox allows removing images entirely. The
mixin is reusable for any future admin model with Cloudinary fields.

## Claude Implementation Notes
- utils/admin_widgets.py: New CloudinaryUploadWidget with multipart form support, preview, file input, URL fallback, and clear checkbox
- utils/admin_mixins.py: New CloudinaryUploadMixin that injects upload widgets via get_form(), hides public_id fields via get_exclude(), and handles upload/clear/delete in save_model()
- templates/admin/widgets/cloudinary_upload.html: Widget template with image preview, file input, URL input, and clear checkbox
- users/cloudinary_service.py: Added generic upload_image() class method for admin use
- contributions/admin.py: Applied CloudinaryUploadMixin to FeaturedContentAdmin with 4 image field pairs configured, removed Cloudinary Metadata fieldset
@rasca rasca merged commit d35d928 into dev Mar 17, 2026
1 check passed
@rasca rasca deleted the main branch March 17, 2026 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant