AttributeError: 'file' object has no attribute '_committed'
<p>I have a DjangoFileField in my model. I am trying to convert the type of the audio from that FielField to mp3 and then again trying to save it. But after converting the type and exporting it using pydub it is returning the following error  </p>

<pre><code>AttributeError: 'file' object has no attribute '_committed'
</code></pre>

<p>My code is like this  </p>

<pre><code>def get_from_function(AudioSegment, format):

    form = "from_{0}".format(format)
    print form
    if hasattr(AudioSegment, form):
        return getattr(AudioSegment, form)
    return None


    audio = request.FILES.get('audio', None)
    if audio:
        name_list = audio.name.rsplit(".")
        voice_format =name_list[1]
        from_format = get_from_function(AudioSegment, voice_format)
        if from_format and callable(from_format):
            sound = from_format(audio)
            audio = sound.export("media/{0}".format(name_list[0]), mp3")
</code></pre>

<p>when i print the <code>audio</code> it prints   </p>

<pre><code>&lt;open file 'media/barsandtone', mode 'wb+' at 0x7f771e5e2f60&gt;
</code></pre>

<p>and when i print the type of file it prints    </p>

<pre><code>&lt;type 'file'&gt;
</code></pre>

<p>but when i assign the audio field to django model like  </p>

<pre><code>Mymodel.objects.create(audio=audio)
</code></pre>

<p>it gives error   </p>

<pre><code>AttributeError at /create/
'file' object has no attribute '_committed'
</code></pre>

<p>What is the correct way to save the exported file into django model</p>