I am trying to create an app that sends a video file to a encoding service an from the encoding service to an AWS bucket. This would required me to make the file available to a function that handles the upload and update the url of the fil location before saving the object from the admin.
The upload to encoder process returns information in JSON format that show errors or success. I have had no trouble with trying it out on the client side of the site. However I am not quite sure how to go about it using Django’s admin.
I have looked at the docs and found the ModelAdmin.add_view(). I am not sure how I can get the name and the path of the uploaded file since this is required for the function uploads to the encoder.
I realize that it is probable best to save all the other information once the process is complete since the encoder sends a ping back.
How do I access the uploaded file to so I can run the encode function on it and is the a way to save all the other information when the service receives a ping back from the service?
Edit:
As requested a timeline/flow of events.
This is how it works right now in the front end:
- File is uploaded
- file_upload_handle checks file size and duration
- file is uploaded to encoder(during upload the encoder service sends JSON with status info)
- the encoder sends the file to AWS and a pingback to the server on success
What I am trying to make sure that the uploading to the encoder is done outside of models.py since it returns some import information in the JSON response which can be used to throwback an error.
It would probably be better to create a custom storage.
If you only want to override the save function of the admin, then you should override save_model():
This code is taken from
django/contrib/admin/options.py, which presents many methods you can override.Or, you could connect a function to the pre_save signal as such:
This will make
encode_uploadto be called before an instance of YourModelClass is saved. Be it in the admin, in other views, anywhere save() is called.Note that the slot (function/callback connect to the signal) should be connected when the site is started. Use it in
models.pyfor example.Learn more about signals.