I have two models both having FileField
like so:
class OriginalFile(models.Model):
docfile = models.FileField(upload_to=file_path)
class RevisedFile(models.Model):
newfile = models.FileField(upload_to=revisedfile_path)
originalfile = models.ForeignKey(OriginalFile, on_delete=models.PROTECT)
As you see, when uploading a file for the first time, it gets uploaded to file_path
in the OriginalFile
model. However, if a user uploads a revised edition of the same file, it gets saved to revisedfile_path
in the RevisedFile
model.
The normal user doesn't have the rights to revise a file by herself(which is why I'm not replacing the original file at that moment). If a manager accepts the revised file, then following things need to happen:
- Replace the
docfile
ofOriginalFile
withnewfile
ofRevisedFile
- Delete the related instance of
RevisedFile
along with itsnewfile
saved in the directory.
The names of docfile
and newfile
can be assumed to be the same. I have no idea how to approach this problem. Any kind of help woould be much appreciated. Thanks.