Problem with adding image files to my object.

26 views
Skip to first unread message

N!KH!L

unread,
Mar 4, 2021, 9:32:07 AM3/4/21
to Django users
Hello everyone!
I am trying to convert multiple audio files to image files. 
After data processing when i try to add o/p(image) using 
below code,
I am getting an error "'list' object has no attribute '_committed'" in my browser

Here is my views.py
def home(request):
 if request.method == 'POST':
        
        audios = request.FILES.getlist('audios')
        for s in audios:
            sample_rate, sound_data = scipy.io.wavfile.read(s)
            data_points = sound_data[:, 0].size
            length = data_points / sample_rate
            data_shape = sound_data.shape
            data_type = sound_data[:, 0].dtype
            y_fourrier = np.abs(fft(sound_data[:,0]))
            x_fourrier = np.linspace(0.0, sample_rate, data_points, endpoint=True)
            y_fourrier = y_fourrier[0:data_points // 2 + 1]
            x_fourrier = x_fourrier[0:data_points // 2 + 1]
            #transform to log scale
            y_fourrier_db = np.log10(y_fourrier)
            photo=plt.plot(x_fourrier, y_fourrier_db)
            image=Image.objects.create(
                photo=photo,
            )
 img = Image.objects.all()
 return render(request, 'myapp/home.html', {'img':img})

and this is my model.py
class Image(models.Model):
    photo = models.ImageField(null=False, blank=False) 
class Audio(models.Model):
    sound = models.FileField(null=False, blank=False)

Ryan Nowakowski

unread,
Mar 7, 2021, 2:14:12 PM3/7/21
to Django users
On Thu, Mar 04, 2021 at 05:16:55AM -0800, N!KH!L wrote:
> Hello everyone!
> I am trying to convert multiple audio files to image files.
> After data processing when i try to add o/p(image) using
> below code,
> *I am getting an error "'list' object has no attribute '_committed'" in my
> browser*
>

Can you please reply with the full traceback? It's hard to help debug
with just the error message.
Reply all
Reply to author
Forward
0 new messages