I am creating a cleanup script for Django Filer, so that if an image is not in use, e.g. it's not related to any other model, then I'd like to delete the image.
I can't figure out how to detect if the image is related to any other objects though. Does anybody know how to achieve this?
You can view this information when you press the delete button and are on the delete confirmation page, but I'm not sure how Django has done this.
Any help would be much appreciated.
Edit
To clarify,
from filer.models import Image
i = Image.objects.all().first()
i.get_all_related_objects.count()
The last line of the above is not valid, but this is what I'm trying to achieve, so if this is 0, then I can remove the file.