DEV Community

Ashutosh Mishra
Ashutosh Mishra

Posted on

How to download data in excel sheet through django api

class Task(models.Model):

    name=models.CharField(max_length=20)
    address=models.CharField(max_length=50)
    
    def __str__(self):
        return str(self.name)
        
#viewset

plan=Task.objects.all()

b=[]

for i in plan:

    b.append({
        "name":i.name,
        "address":i.address,
        
    })
return Response({"data":b})

output should be

0 name:address

1 Ashu:Gurgaon

Top comments (0)