class ProductResource(resources.ModelResource):
class Meta:
model = Product
exclude = ('pub_date','modified_date',)
import_id_fields = ('CD-SKU',)
class ProductAdmin(ImportExportModelAdmin):
resource_class = ProductResource
错误是:
Line number: 1 - u'CD-SKU'
0H041501, VOL3380235300029, 3380235300029, B00FIZJI0K, 11.59, None, None, None, None, None, None, None, None, None
Traceback (most recent call last):
File "/home/mws/Env/mws_prod/local/lib/python2.7/site-packages/import_export/resources.py", line 434, in import_row
instance, new = self.get_or_init_instance(instance_loader, row)
File "/home/mws/Env/mws_prod/local/lib/python2.7/site-packages/import_export/resources.py", line 258, in get_or_init_instance
instance = self.get_instance(instance_loader, row)
File "/home/mws/Env/mws_prod/local/lib/python2.7/site-packages/import_export/resources.py", line 252, in get_instance
return instance_loader.get_instance(row)
File "/home/mws/Env/mws_prod/local/lib/python2.7/site-packages/import_export/instance_loaders.py", line 31, in get_instance
field = self.resource.fields[key]
KeyError: u'CD-SKU'
在阅读了相关问题后,我删除了本机自动生成的 id 并使用我自己的字段作为主要字段。在 Resource 类中提到了它。但它仍然无法导入。
将不胜感激所有的帮助。谢谢!