DEV Community

Ashutosh Mishra
Ashutosh Mishra

Posted on

“message”: “'ModelBase' object is not iterable”, Django

I was trying to get data on the excel sheet ,i am getting this error

class Task(models.Model):

Name=models.CharField(max_length=50,null=False,blank=True,primary_key=True)
Image1=models.FileField(blank=True, default=""
 upload_to="media/images",null=True)
Image2=models.FileField(blank=True, default="",
 upload_to="media/images",null=True)
Date=models.DateField(null=True,blank=True)

def __str__(self):
    return str(self.Name)

plans=Task.objects.all()

workbook=xlsxwriter.Workbook('data.xlsx')

worksheet=workbook.add_worksheet()

b=[]

            for plan in plans:

                b.append({
                   "Name":plan.Name,
                   "Image1":plan.Image1.url,
                   "Image2":plan.Image2.url,
                   "Date":plan.Date, 
                    
                })

            row=1
            col=0

            for Name,Image1,Image2,Date in (Task):

                worksheet.write(row,col,Name)

Top comments (0)