Answer the question
In order to leave comments, you need to log in
Django 4 - how to delete a file when deleted from admin?
Hello.
1. When adding a file for a model in the admin panel, it is possible to check the box and, when resaving, delete this file from the database. But how to delete this file physically?
2. There are many examples on the Internet on how to delete a file when deleting the model itself. And how to delete all files, if there are several.
Thank you.
Answer the question
In order to leave comments, you need to log in
What does "how" mean? Answer the question: how to get all the files associated with the model? Now turn it into a model method
def get_all_my_files(self) -> list[str]:
result = []
result.extend(get_from_here())
result.extend(and_from_there())
return result
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question