How can solve this problem to apply that for loop for every line of that csv file?

When i try this for loop to add data with a csv file it just adds the data of last line in csv file.

from django.db import models

# Create your models here.
class product(models.Model):
    Number=models.CharField( max_length=40 )
    name=models.CharField(max_length=40 )
    image=models.CharField(max_length=500)
    description=models.CharField(max_length=500)
    price=models.CharField(max_length=50)
    buy=models.CharField(max_length=100)

p=product()

with open('b.csv', 'r')  as f:
    for line in f:  
       line =  line.split(',')  
       p.Number=line[0]
       p.name=line[1]
       p.image=line[2]
       p.description=line[3]
       p.price=line[4]
       p.buy=line[5]
       p.save()
 
f.close()

csv file:

Number,name,image,description,price,buy
1,a,1,1,1,1
2,bb,2,2,2,2
3,aa,3,3,3,3
4,bd,4,4,4,4
5,d,5,5,5,5
6,e,6,6,6,6

there is just one product with the data of last line of csv file:

enter image description here

enter image description here

How can solve this problem to apply that for loop for every line of that csv file?

You could try using:

for line in f.index:
    #write your code here
Back to Top