How can I call the custom method model into view ?

I’ve written audio_conversion(request) function in to get custom object/method from But I don’t know if this the best way.

class DemoMCall(models.Model):
    tenant_name = models.CharField(max_length=200)
    rid = models.PositiveBigIntegerField(primary_key=True)
    audio_file = models.FileField( upload_to = 'uploads/' )

    def get_path_audio(self):
        return self.audio_file 

And I call it from a like this:

def audio_conversion(request):

    file = "C:\\Users\\Downloads\\Recordings\\sox\\Recordings"
    # Get audio path 
    rec_lis  = DemoMCall.objects.all()

    for i in rec_lis:
        name_file = i.get_path_audio()

        full_path_infile = file + name_file + ".ul" # -> the input
        full_path_outfile = file + name_file + ".wav" # -> the output

        if os.path.isfile(full_path_infile):
            command2 = " D:\\Quality-Management-main\\sox-14-4-2\\sox " + full_path_infile + full_path_outfile + " rate -v 8000"
            output = os.popen(command2)

    return render(request, 'qualityManagement/command.html' , {'output' : output} )

Any ideas on what I do to solve this ? Thanks for help!

It’s not clear from what you’re written what you’re trying to achieve here, or what the problem you’re encountering is.

It looks like, given that you’re querying for all rows in DemoMCall, that you’re trying to do some type of bulk conversion.

If so, it seems to me that you’d want to do this in a management command and not a view. My guess is that this would take too long to complete in a view.