Question

I have a list like this:

list = [['Amy Pond', 'R$30 of awesome for R$10', '10.0', '5', '456 Unreal Rd', "Tom's Awesome Shop\n"], ['Marty McFly', 'R$20 Sneakers for R$5', '5.0', '1', '123 Fake St Sneaker', 'Store Emporium\n'], ['Snake Plissken', 'R$20 Sneakers for R$5', '5.0', '4', '123 Fake St Sneaker', 'Store Emporium']]

My model is:

class Vendas(models.Model):
    purchasername=models.CharField(u'Nome do Comprador',max_length=100)
    itemdescription=models.CharField(u'Descrição do Item',max_length=100)
    itemprice=models.IntegerField(u'Preço do Item')
    purchasecount=models.IntegerField(u'Quantidade comprada')
    merchantaddress=models.CharField(u'Endereço do comprador',max_length=100)
    merchantname=models.CharField(u'Nome do Comprador',max_length=100)

I want to load this list as is into the table Vendas.

Can someone help me?

Was it helpful?

Solution

Try this:

for i in list:
    a = Vendas(purchasername=i[0], itemdescription=i[1], itemprice=i[2], purchasecount=i[3], merchantaddress=i[4], merchantname=i[5])
    a.save()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top