I am trying to set up django-import-export to handle my data which is stored in spreadsheets.
The spreadsheets don't contain foreign keys as IDs, but rather they contain the (also unique) names of the correlating object.
Within my database I will have foreign key relationships of Teachers
who work at Schools
which are located in Cities
.
Imagine this to be the models (excerpt):
class School(models.Model):
city = models.ForeignKey(City)
name = models.CharField(max_length=200)
class Teacher(models.Model):
school = models.ForeignKey(School)
name = models.CharField(max_length=200)
The spreadsheet for teachers could look like this:
school,name
Central Grammar School,John Smith
West Primary,Jane Doe
West Primary,John Doe
...,...
How do I build the SchoolResource
model so that during import it will accept the names instead of the IDs?
(I cannot just take the IDs from the database because the idea is, at one point, to start the database from scratch with only the spreadsheet data, which will not contain any IDs.)