我使用 django import-export,但无法导入 excel 文件,出现错误:
Line number: 1 - 'id'
Traceback (most recent call last):
File "C: \ mat4 \ env \ lib \ site-packages \ import_export \ resources.py", line 317, in import_data
instance = new self.get_or_init_instance (instance_loader, row)
File "C: \ mat4 \ env \ lib \ site-packages \ import_export \ resources.py", line 149, in get_or_init_instance
instance = self.get_instance (instance_loader, row)
KeyError: 'id'
Line number: 2 - 'id'
Traceback (most recent call last):
File "C: \ mat4 \ env \ lib \ site-packages \ import_export \ resources.py", line 317, in import_data
instance = new self.get_or_init_instance (instance_loader, row)
File "C: \ mat4 \ env \ lib \ site-packages \ import_export \ resources.py", line 149, in get_or_init_instance
instance = self.get_instance (instance_loader, row)
KeyError: 'id'
我的模型:
class Essai_Temperature(models.Model):
name = models.ForeignKey(Material, verbose_name=_('name'))
nature_unit = models.ForeignKey(Property, verbose_name=_('category'))
choix = ChainedForeignKey(Physic, verbose_name=_('properties'), null=True, blank=True,
related_name='Essai_Temperature_choix',
chained_field="nature_unit",
chained_model_field="name",
show_all=False,
auto_choose=True)
valT= models.FloatField(_('temperature'),blank=True, null=False)
val10= models.FloatField(_('value'), blank=True, null=False)
val_ref= models.CharField(_('reference of the data'), max_length=50, default='0')
资源.py
class Essai_Temperature_Resource(resources.ModelResource):
class Meta(object):
model = Essai_Temperature
管理员.py
class Essai_TemperatureAdmin(ImportExportModelAdmin):
resource_class = Essai_Temperature_Resource
list_display = ('name', 'nature_unit', 'choix', 'valT', 'val10', 'val_ref')
ordering = ('name__name', 'nature_unit__name', 'choix__lapropriete', 'valT',)
list_filter = ('name', 'nature_unit', 'choix')
和excel文件
1 CT55 Mechanical Hardness - Vickers (Mpa) 44 125 EF-01
2 CT55 Mechanical Hardness - Vickers (Mpa) 44 127 EF-02
我不明白“id”的问题?