Is there a way to just download a file that contains only the field titles?
For example, the download template button will download a file that has all the necessary fields as shown in the help text.
The downloaded file would look like this:
Any help is appreciated.
Here is one way. You need to declare a resource and override the export()
method so that it creates a new Dataset containing only headers.
class BookResource(ModelResource):
class Meta:
model = Book
def export(self, queryset=None, *args, **kwargs):
data = super().export(queryset, args, kwargs)
return tablib.Dataset(headers=data.headers)