bruvellu / cifonauta

Marine biology image database by CEBIMar/USP
http://cifonauta.cebimar.usp.br
GNU General Public License v3.0
21 stars 5 forks source link

Simplify model instance creation during file upload using only `Media` (not `LoadedMedia`) #246

Closed bruvellu closed 10 months ago

bruvellu commented 11 months ago

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.

bruvellu commented 10 months ago

Removal of LoadedMedia in 06f4d8eb7e7a334fb29d7f7ed780287d76e844b6. New UUIDField and new filename logic in d95bddc0f376177d140feafdfd1fd6548e1b7f6b.