我使用自定义字段使用django 1.9在s3上传图像。我想删除模型实例时从s3删除图像。我用ImageField的delete()方法尝试了post_delete信号,但由于我使用自定义字段无法实现结果。有关如何实现这一目标的任何建议吗?
答案 0 :(得分:0)
from django.db.models.signals import pre_delete
pre_delete.connect(delete_image, dispatch_uid="delete_image")
def delete_image(sender, instance, **kwargs):
for field_name in instance._meta.get_fields():
try:
field = getattr(instance, field_name)
except:
field = None
if isinstance(field, your_custom_field):
your_app_utils.clean_images(field.get_images())