Django Csv Importer整数错误

时间:2012-06-26 02:36:40

标签: python django django-models

我正在使用最新的Django Csv Importer:http://django-csv-importer.readthedocs.org/en/latest/index.html

包含整数的CSV行2没有任何空行。他们都是数字。我进入CSV并将所有带有数字的行转换为整数,然后重新上载文件,但我仍然收到此错误:

line 182, in import_data
return importer.import_data(data)
File "/.../lib/python2.7/csvImporter/model.py", line 282, in import_data self.process_line(data, line, lines, line_number)
File "/.../lib/python2.7/csvImporter/model.py", line 299, in process_line
    raise CsvDataException(line_number, field_error =  e.message)

CsvDataException: Line 2: invalid literal for int() with base 10: ''

我的模型设置如下:

class Character(models.Model):
    name = models.CharField(max_length=128)
    points = models.IntegerField()
    description = models.TextField()
    image = models.ManyToManyField(Image)
    dice = models.IntegerField(blank=True, null=True)

    def __unicode__(self):
        return self.name

class CsvCharacterUpload(CsvDbModel):
        name = models.CharField(max_length=128)
        points = models.IntegerField()
        description = models.TextField()
        image = models.ManyToManyField(Image)
        dice = models.IntegerField(blank=True, null=True)

    class Meta:
        dbModel = Character
        delimiter = ","
        has_header = True

1 个答案:

答案 0 :(得分:0)

CSVCharacterUpload中的CharField,IntegerField等应该是在django-csv-importer中定义的,而不是在django.models中定义的。

即从csv_importer.fields导入CharField,IntegerField

我建议切换到django-adaptors,因为不再维护django-csv-importer。