A
A
Alexander2018-06-28 16:05:34
Django
Alexander, 2018-06-28 16:05:34

How to properly work/delete with a model that is related to many other models?

Let's say there are about 20 - 30 models in the project, and all of them are connected via Fk or ManyToMany with the File model .
file model:

class File(models.Model):
    file = models.FileField(upload_to=upload_name)

After the expiration of time, the File model accumulated a lot of records in the database that are not associated with more than one model.
It would seem that the answer is simple, run cron every night and delete entries from the database that do not have bundles. Well, what if I have several such models of the File type File , Tag, Notes, ... ? How correct is my method, won't it load the server too much, all the same cycles, requests to the database? please share advice/best practice in this matter.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alternativshik, 2018-06-28
@alternativshik

model has on_delete=models.CASCADE

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question