Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions djqscsv/djqscsv.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,18 @@ def write_csv(queryset, file_obj, field_header_map=None,

try:
field_names = values_qs.field_names
extra_columns = list(values_qs.query.extra_select)
if extra_columns:
# TODO: provide actual ordering
field_names += extra_columns

except AttributeError:
# in django1.5, empty querysets trigger
# this exception, but not django 1.6
raise CSVException("Empty queryset provided to exporter.")

writer = csv.DictWriter(file_obj, field_names)

# verbose_name defaults to the raw field name, so in either case
# this will produce a complete mapping of field names to column names
if use_verbose_names:
Expand All @@ -82,8 +89,6 @@ def write_csv(queryset, file_obj, field_header_map=None,
_field_header_map = field_header_map or {}
merged_header_map = name_map.copy()
merged_header_map.update(_field_header_map)

writer = csv.DictWriter(file_obj, field_names)
writer.writerow(merged_header_map)

for record in values_qs:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='django-queryset-csv',
version='0.2.0',
version='0.2.1',
description='A simple python module for writing querysets to csv',
long_description=open('README.md').read(),
author=author,
Expand Down