-
Notifications
You must be signed in to change notification settings - Fork 223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Delete image from storage when removing image within the widget #420
Comments
I wish this feature be added too. My tentative suggestion of 2 solution:
|
That would be a cool feature to have. |
i'm do it by that demo way import os
from django.dispatch import receiver
from django.db.models.signals import post_delete
from mindkeeper.settings import MEDIA_ROOT, MEDIA_URL
from .models import Cards
@receiver(post_delete, sender=Cards)
def on_delete(sender, **kwargs):
images = []
html_str = kwargs['instance'].content
while "img" in html_str:
left_enter = html_str.find('<img')
html_str = html_str[left_enter:]
right_enter = html_str.find('>') + 1
images.append(html_str[:right_enter])
html_str = html_str[right_enter:]
for image in images:
left_enter = image.find(MEDIA_URL)
image = image[left_enter + len(MEDIA_URL):]
right_enter = image.find('"')
path = os.path.join(MEDIA_ROOT / image[:right_enter])
os.remove(os.path.join(path)) where Cards it's something like post in blog |
I was wondering if it is possible to delete images from storage when they are removed within the summernote widget.
Whenever an image is dragged into the widget, it would automatically be uploaded even before 'save'.
I tried using django-cleanup but it only works on FileField and ImageField.
Is 'delete from storage' feature built into django-summernote?
If so, how may I proceed?
I guess workaround solution would be to upload images as ImageField and use the image in the widget as img src url after upload.
Thanks.
The text was updated successfully, but these errors were encountered: