My model File has as main purpose to link multiple files for one Invoice.
class File(models.Model):
invoice = models.ForeignKey(Invoice, related_name = 'files', on_delete = models.CASCADE)
file = models.FileField(upload_to = 'storage/invoicing/')
def delete(self, *args, **kwargs):
self.file.delete()
return super(File, self).delete(*args, **kwargs)
When i delete one instance of my model File, the file stored in storage/invoicing is also deleted because of my modified delete() method.
However, if i delete the instance from the parent model Invoice, the file is not deleted. Even with the File instance being removed from the database, the file is still acessable.
How can i code the parent model to delete everything from the children model, including the files?
I've searched a bit and i know that probably signals like post_delete can help me here, but i really don't know how to code it.