Thursday, March 4, 2021

Problem with adding image files to my object.

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)

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4304ca27-dde1-46f6-9da9-c80ec8c986c8n%40googlegroups.com.

No comments:

Post a Comment