Managing files name

Hello everyone,

I’m a beginner on Django.

I want to get the each full filenames after I read the path folder based on id in model.

Any pointers in the right direction would be greatly appreciated

Please don’t post screenshots here. When you want to share code, copy/paste the code into your message, surrounded by lines of three backtick - ` characters. This means you’ll have a line of ```, then your code, then another line of ```.

Can you be more specific with what you’re trying to accomplish here? Perhaps provide an example? Or perhaps explain with more detail what your objective is?

Ok , Sorry about that :pray:

I have audio files and I want to read the (path folder) + (path filename) based on the id model.

I discovered some resources that upload audio files as object models. but I don’t want to handle as the model, I just want to read the path.

After that, I want to calling the path audio into HTML for paly/stop audio.

The models.py file:

def get_path_filename(instance):
    return os.path.join('rec_{0}{1}'.format(instance.DemoMCall.rid, instance.DemoMCall.info_agent))

The views.py file:

def read_audio(request):

   rec_list = DemoMCall.objects.all()

   filename = get_path_filename

   file_path = os.path.join(settings.STATIC_ROOT, filename )

   data =  winsound.PlaySound(file_path, winsound.SND_FILENAME | winsound.SND_ASYNC)

   return render(request, 'qualityManagement/audio.html', { 'file_path' : file_path , 'data': data})

The audio.html file:

<audio controls>
    <source src="{{ data }}" type="audio/wav" >
</audio>

Yes, you do very much want to work with the models for uploaded files.

Keep in mind that the internal path where files are stored is not the same as the URL path exposed to the browser through HTML.

Additionally, if files are allowed to be uploaded through Django, they may not even be stored with the same file name.

Work with files properly, it’s going to end up being a lot easier that way.

I’ve already read what you said, and I’ve read it again, and I still can’t get it to work.

Do I use fileField(upload to = " ") in model.py or read the path file in views.py?

My objective I’d like to use audio files without storing them in Django

Any sort of help would be highly appreciated

Advice? Don’t fight the framework. If you’re going to build this site using Django, use Django’s facilities for managing the files.

1 Like

Thank you very much. I appreciated your help

I read this documentation: Managing files Django. Do I use Static files to handle audio files or use to file storage systems to stores audio files?

I want to do a list of audios record website