我有一个从 csv 文件导入的导入脚本,但一个值(客户)可以重复。因此,例如名称总是不同的,但客户 (john) 可以有 5 个条目。我需要将其导入到名为 customer 的外键中以供其他用途。但我不知道该怎么做。
我的模型
class Route_destinguisher(models.Model):
name = models.CharField(max_length=100)
customer = models.CharField(max_length=100)
comment = models.TextField(blank=True)
active = models.BooleanField(default=True)
rd = models.CharField(max_length=20, default='33763:264')
def __unicode__(self):
return self.name
我的导入代码
dataReader = csv.reader(open(csv_filepathname), delimiter=',', quotechar='"')
for row in dataReader:
route_distinguisher = Route_destinguisher()
route_distinguisher.customer=row[2].split("-")[0]
route_distinguisher.name=row[2]
route_distinguisher.rd=row[1].replace('\t',':')
route_distinguisher.save()
print row