I found some information on extending and changing the save()
method on my model, but a few other people mentioned that it was bad practice to do that, and one should instead modify the admin form.
Extracting the audio from a mp4 is easy using moviepy
, I just need to run these lines:
from moviepy.editor import *
audio = VideoFileClip("test-file.mp4").audio
audio.write_audiofile("audio.mp3")
However, I do not know where to put this within my model to ensure it gets run and saves the correct file.
My model looks like this:
Class MyModel(models.Model):
audio = models.FileField(upload_to=update_filename)
It's important this code is executed before the file gets saved, and the audio file is the one getting saved to the audio
attribute of my model.