B
B
bituke2021-03-23 18:37:24
Django
bituke, 2021-03-23 18:37:24

How to add audio files by url to the database using django?

Let's say I have a song on my computer that I want to add to my django project. But I want to do this not through the admin panel or the form, but directly, through the path.
more details:
there is a model

class Audio(models.Model):
    url = models.FileField(upload_to='records/%m/')

Now, in the view, I need to add audio from my computer to the database through this model, how I try to do it:
audio.url = '/storage/usbdisk1/mikopbx/astspool/monitor/2021/03/20/12/mikopbx-1616233798.4_jX36V8.mp3'
audio.save()

How it should look like:
605a0ab1a3917329009852.png
How it looks like:
605a0ae54a05e116147044.png
That is, you need to take these files somehow through the code and add them to the database, but as I can't understand, I can't google it. I will be glad to help.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question