During file upload, a LoadedMedia instance is created, the file is renamed and uploaded to a separate folder. Then, information from LoadedMedia is copied to a new Media instance with lots of manual juggling (with file name/extension, for example).
This process can be streamlined by removing the LoadedMedia model and using simply Media from the beginning of the upload process. To create a Media instance, we only need the file and the user making the upload. They can receive a special status (loaded_media, for example) if we want to open them directly in step2 (maybe useful for batch editing the metadata).
Furthermore, the UUID doesn't need to be hand coded in the view, but it can be a UUIDField from Django in Media. This way, every time a media instance is created, a new UUID is generated. We can then hook a rename_file function in Media to change the file's original name to the UUID. The idea is that all the logic related to Media stays within the Media model for consistency.
During file upload, a
LoadedMedia
instance is created, the file is renamed and uploaded to a separate folder. Then, information fromLoadedMedia
is copied to a newMedia
instance with lots of manual juggling (with file name/extension, for example).This process can be streamlined by removing the
LoadedMedia
model and using simplyMedia
from the beginning of the upload process. To create aMedia
instance, we only need the file and the user making the upload. They can receive a special status (loaded_media
, for example) if we want to open them directly in step2 (maybe useful for batch editing the metadata).Furthermore, the UUID doesn't need to be hand coded in the view, but it can be a UUIDField from Django in
Media
. This way, every time a media instance is created, a new UUID is generated. We can then hook arename_file
function inMedia
to change the file's original name to the UUID. The idea is that all the logic related toMedia
stays within theMedia
model for consistency.