The project I'm working on requires specific column names. Like the current export file has 'Surname' and 'First Name' but I need them to be 'lastname' and 'firstname', respectively.
Create a resource which is a subclass of ModelResource
and override the get_export_headers()
method:
class BookResource(resources.ModelResource):
def get_export_headers(self):
headers = super().get_export_headers()
for i, h in enumerate(headers):
if h == 'Surname':
headers[i] = "lastname"
if h == 'First Name':
headers[i] = "firstname"
return headers
class Meta:
model = Book