I am trying to import excel documents into a Django DB. I have added the following code to admin.py
and model.py
. There seems to be an error in the development of Django. I have read through several different documentations about how to fix this error. But I am still a little lost on how to implement it exactly.
In the Trace it keeps saying that my excel document needs an id
field. There is no id
field in my excel docs nor did I tell my model to look for an id
field.
The documentation that I have found states that I should use get_or_init_instance
here:
https://django-import-export.readthedocs.org/en/latest/import_workflow.html
Any help that you guys could give would be great.
admin.py
class VinCasesAndCampaignsResource(resources.ModelResource):
published = fields.Field(column_name='published_date')
def get_instance(self, instance_loaders, row):
return False
class Meta:
model = VinCasesAndCampaigns
widgets = {}
fields = ('VIN','LatestOpenCaseID','LatestClosedCaseID',
'OpenDate', 'CloseDate', 'HasCampaigns',)
import_id_fields = ['VIN']
export_order = ('VIN',)
exclude = ('id')
model.py
class VinCasesAndCampaigns(models.Model):
VIN = models.CharField(max_length=30)
LatestOpenCaseID = models.DateField()
LatestClosedCaseID = models.DateField()
OpenDate = models.DateField()
CloseDate = models.DateField()
HasCampaigns = models.BooleanField(default = False)
HasOpenCampaigns = models.BooleanField(default = False)
HasCases = models.BooleanField(default = False)
HasEstimates = models.BooleanField(default = False)
HasDwell = models.BooleanField(default = False)
HasClaims = models.BooleanField(default = False)
exclude = ('id',)
Trace:
> Line number: 1 - u"Column 'id' not found in dataset. Available columns
> are: [u'VIN', u'LatestOpenCaseID', u'LatestClosedCaseID', u'OpenDate',
> u'CloseDate', u'HasCampaigns', u'HasOpenCampaigns', u'HasCases',
> u'HasEstimates', u'HasDwell', u'HasClaims']" Traceback (most recent
> call last): File
> "/Users/USER/anaconda/lib/python2.7/site-packages/django_import_export-0.2.8.dev0-py2.7.egg/import_export/resources.py",
> line 342, in import_data instance, new =
> self.get_or_init_instance(instance_loader, row)