Skip to content
Open
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: 6 additions & 3 deletions rest_framework_csv/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class CSVRenderer(BaseRenderer):
header = None
labels = None # {'<field>':'<label>'}
writer_opts = None
to_flat_list = True

def render(self, data, media_type=None, renderer_context={}, writer_opts=None):
"""
Expand Down Expand Up @@ -125,7 +126,7 @@ def flatten_data(self, data):
yield flat_item

def flatten_item(self, item):
if isinstance(item, list):
if isinstance(item, list) and self.to_flat_list:
flat_item = self.flatten_list(item)
elif isinstance(item, dict):
flat_item = self.flatten_dict(item)
Expand Down Expand Up @@ -191,7 +192,9 @@ def fdel(self):

class CSVRendererWithUnderscores (CSVRenderer):
level_sep = '_'


class CSVRendererWithList (CSVRenderer):
to_flat_list = False

class CSVStreamingRenderer(CSVRenderer):

Expand Down Expand Up @@ -240,4 +243,4 @@ class PaginatedCSVRenderer (CSVRenderer):
def render(self, data, *args, **kwargs):
if not isinstance(data, list):
data = data.get(self.results_field, [])
return super(PaginatedCSVRenderer, self).render(data, *args, **kwargs)
return super(PaginatedCSVRenderer, self).render(data, *args, **kwargs)