Skip to content

Conversation

nathan-osman
Copy link
Contributor

The existing xlsx_ignore_headers option allows specific fields to be excluded when enumerating fields in the serializer. This pull request adds the ability to explicitly specify the fields that should be included:

xlsx_specify_headers = ['title', 'age', ...]

The absence of the option will result in the default behavior. A test was added to ensure correct behavior.

The xlsx_ignore_headers option allows specific fields to be excluded when
enumerating the serializer. This adds the ability to explicitly specify the
fields that should be included. The absence of the option will result in the
default behavior.
Copy link

codecov bot commented May 11, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
drf_excel/renderers.py 87.09% <100.00%> (+0.14%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@FlipperPA
Copy link
Member

@nathan-osman Thanks so much for the contributions! We'll get the workflows run today and review this week.


This also works with nested fields, separated with a dot (i.e. `icon.url`).
To include only a specified list of fields, provide them with: `xlsx_specify_headers = [<fields to include>]`. Conversely, to exclude certain fields from your export, provide them with: `xlsx_ignore_headers = [<excluded fields>]`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering whether these 2 options should be mutually exclusive: you could use one option or the other, but not both...

I looked at the Django model forms API with fields and exclude which have a similar concern and they're not mutually exclusive:

exclude is an optional list of field names. If provided, the named fields will be excluded from the returned fields, even if they are listed in the fields argument.

Which -I think- matches the current implementation here. Maybe add a sentence to explain that ignore takes precendence over specify?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants