{"id":18798392,"url":"https://github.com/benkonrath/django-csv-export-view","last_synced_at":"2025-07-18T07:07:13.489Z","repository":{"id":22633313,"uuid":"96888702","full_name":"benkonrath/django-csv-export-view","owner":"benkonrath","description":"Django class-based view for CSV exports","archived":false,"fork":false,"pushed_at":"2024-11-04T15:02:18.000Z","size":103,"stargazers_count":19,"open_issues_count":1,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-06T05:19:44.363Z","etag":null,"topics":["csv","csv-export","django","django-admin"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/benkonrath.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-07-11T12:05:11.000Z","updated_at":"2024-11-04T15:02:22.000Z","dependencies_parsed_at":"2024-06-21T05:43:16.210Z","dependency_job_id":"ea8cc54c-7fd9-4081-9b41-78dba9b4317e","html_url":"https://github.com/benkonrath/django-csv-export-view","commit_stats":{"total_commits":96,"total_committers":3,"mean_commits":32.0,"dds":0.03125,"last_synced_commit":"067939ccdedd6919bfaf4cf589b1aca7b4e05a64"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/benkonrath/django-csv-export-view","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benkonrath%2Fdjango-csv-export-view","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benkonrath%2Fdjango-csv-export-view/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benkonrath%2Fdjango-csv-export-view/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benkonrath%2Fdjango-csv-export-view/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/benkonrath","download_url":"https://codeload.github.com/benkonrath/django-csv-export-view/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benkonrath%2Fdjango-csv-export-view/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265716306,"owners_count":23816354,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csv","csv-export","django","django-admin"],"created_at":"2024-11-07T22:11:49.726Z","updated_at":"2025-07-18T07:07:13.467Z","avatar_url":"https://github.com/benkonrath.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# django-csv-export-view\n\nA Django class-based view for CSV export.\n\n[![Tests](https://github.com/benkonrath/django-csv-export-view/actions/workflows/tests.yml/badge.svg)](https://github.com/benkonrath/django-csv-export-view/actions/workflows/tests.yml)\n\n## Features\n\n* Easy CSV exports by setting a Django `model` and a `fields` or `exclude` iterable\n* Works with existing class-based view mixins for access control\n* Generates Microsoft Excel friendly CSV by default\n* Proper HTTP headers set for CSV\n* Easy to override defaults as needed\n* Easy integration into Django Admin\n\n## Installation\n\n`pip install django-csv-export-view`\n\n## Examples of basic options\n\nSpecify a `model` and `fields`. Optionally override `get_queryset()`.\n```python\nfrom csv_export.views import CSVExportView\nfrom .models import MyModel\n\nclass DataExportView(CSVExportView):\n    model = MyModel\n    fields = (\"field\", \"related\", \"property\")\n\n    # When using related fields you will likely want to override get_queryset()\n    # to use select_related(), prefetch_related() or generally filter the results.\n    def get_queryset(self):\n        return super().get_queryset().select_related(\"related\")\n        # -- OR --\n        return super().get_queryset().prefetch_related(\"related\")\n        # -- OR --\n        return queryset.exclude(deleted=True)\n        # etc\n```\n\nYou can also use related fields and properties.\n```python\nfrom csv_export.views import CSVExportView\nfrom .models import MyModel\n\nclass DataExportView(CSVExportView):\n    model = MyModel\n    fields = (\"field\", \"related__field\", \"property\")\n```\n\n`__all__` is supported if you want all fields. Model properties are not included with `__all__`.\n```python\nfrom csv_export.views import CSVExportView\nfrom .models import MyModel\n\nclass DataExportView(CSVExportView):\n    model = MyModel\n    fields = \"__all__\"\n```\n\n`exclude` can be used instead of `fields`.\n```python\nfrom csv_export.views import CSVExportView\nfrom .models import MyModel\n\nclass DataExportView(CSVExportView):\n    model = MyModel\n    exclude = (\"id\",)\n```\n\nOverride `get_fields()` for dynamic control of the fields.\n```python\nfrom csv_export.views import CSVExportView\nfrom .models import MyModel\n\nclass DataExportView(CSVExportView):\n    model = MyModel\n\n    def get_fields(self, queryset):\n        fields = [\"username\", \"email\"]\n        if self.request.user.is_superuser:\n            fields.append(\"birth_date\")\n        return fields\n```\n\n## Basic options\n\n`fields` / `exclude`: An iterable of field names and properties. You cannot set both `fields` and `exclude`.\n`fields` can also be `\"__all__\"` to export all fields. Model properties are not included when `\"__all__\"` is used.\nRelated field can be used with `__`. Override `get_fields(self, queryset)` for custom behaviour not supported by the\ndefault logic.\n\n`model`: The model to use for the CSV export queryset. Override `get_queryset()` if you need a custom queryset.\n\n## Examples of advanced options\n\n`header`, `specify_separator` and `filename` can be use for more customization.\n```python\nfrom csv_export.views import CSVExportView\nfrom .models import MyModel\n\nclass DataExportView(CSVExportView):\n    model = MyModel\n    fields = \"__all__\"\n    header = False\n    specify_separator = False\n    filename = \"data-export.csv\"\n```\n\nUsing `verbose_names` can be turned off.\n```python\nfrom csv_export.views import CSVExportView\nfrom .models import MyModel\n\nclass DataExportView(CSVExportView):\n    model = MyModel\n    fields = \"__all__\"\n    verbose_names = False\n```\n\nOverride `get_filename()` for dynamic control of the filename.\n```python\nfrom django.utils import timezone\nfrom csv_export.views import CSVExportView\nfrom .models import MyModel\n\nclass DataExportView(CSVExportView):\n    model = MyModel\n    fields = \"__all__\"\n\n    def get_filename(self, queryset):\n        return \"data-export-{!s}.csv\".format(timezone.now())\n```\n\n## Advanced options\n\n`header` - *boolean* - Default: `True`  \nWhether to include the header in the CSV.\n\n`filename` - *string* - Default: Dasherized version of `verbose_name_plural` from `queryset.model`.  \nOverride `get_filename(self, queryset)` if a dynamic filename is required.\n\n`specify_separator` - *boolean* - Default: `True`  \nWhether to include `sep=\u003csepaator\u003e` as the first line of the CSV file. This is useful for generating Microsoft\nExcel friendly CSV.\n\n`verbose_names` - *boolean* - Default: `True`  \nWhether to use capitalized verbose column names in the header of the CSV file. If `False`, field names are used\ninstead.\n\n## CSV Writer Options\n\nExample:\n```python\nfrom csv_export.views import CSVExportView\nfrom .models import MyModel\n\nclass DataExportView(CSVExportView):\n    model = MyModel\n    fields = \"__all__\"\n\n    def get_csv_writer_fmtparams(self):\n        fmtparams = super().get_csv_writer_fmtparams()\n        fmtparams[\"delimiter\"] = \"|\"\n        return fmtparams\n```\n\nOverride `get_csv_writer_fmtparams(self)` and return a dictionary of csv write format parameters. Default format\nparameters are: dialect=\"excel\" and quoting=csv.QUOTE_ALL. See all available options in the Python docs:\n\nhttps://docs.python.org/3.11/library/csv.html#csv.writer\n\n## Django Admin Integration\n\nExample:\n```python\nfrom django.contrib import admin\nfrom csv_export.views import CSVExportView\nfrom .models import MyModel\n\n@admin.register(MyModel)\nclass DataAdmin(admin.ModelAdmin):\n    actions = (\"export_data_csv\",)\n\n    def export_data_csv(self, request, queryset):\n        view = CSVExportView(queryset=queryset, fields=\"__all__\")\n        return view.get(request)\n\n    export_data_csv.short_description = \"Export CSV for selected Data records\"\n```\n\n## Contributions\n\nPull requests are happily accepted.\n\n## Alternatives\n\nhttps://github.com/django-import-export/django-import-export/\n\nhttps://github.com/mjumbewu/django-rest-framework-csv\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenkonrath%2Fdjango-csv-export-view","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbenkonrath%2Fdjango-csv-export-view","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenkonrath%2Fdjango-csv-export-view/lists"}