Django class-based view for CSV exports
Project description
# django-csv-export-view
A Django class-based view for CSV export.
[](https://travis-ci.org/benkonrath/django-csv-export-view)
## Features
* Easy CSV exports using the familiar `model` and `fields` / `exclude` pattern
* Works with your existing class-based view mixins for access control
* Generates Micosoft Excel friendly CSV by default
* Easy to override defaults as needed
* Proper HTTP headers set for CSV
## Quick Start
Examples:
```python
class DataExportView(CSVExportView):
model = Data
fields = ('field1', 'field2__related_field', 'property1')
class DataExportView(CSVExportView):
model = Data
fields = '__all__'
class DataExportView(CSVExportView):
exclude = ('id',)
def get_queryset(self):
queryset = super(DataExportView, self).get_queryset()
return queryset.filter(deleted=True)
```
`fields` / `exclude`: An interable of field names and properties. You cannot set both `fields` and `exclude`.
`fields` can also be `'__all__'` to export all fields. Model properties are not included when `'__all__'` is used.
Related field can be used with `__`.
`model`: The model to use for the CSV export queryset. Override `get_queryset()` if you need a custom queryset.
## Further Customization
Examples:
```python
class DataExportView(CSVExportView):
model = Data
fields = '__all__'
header = False
specify_separator = False
filename = 'data-export.csv'
class DataExportView(CSVExportView):
model = Data
fields = '__all__'
def get_filename(self, queryset):
return 'data-export-{!s}.csv'.format(timezone.now())
```
`header` - *boolean* - Default: `True`
Whether or not to include the header in the CSV.
`filename` - *string* - Default: Dasherized version of `verbose_name_plural` from `queryset.model`.
Override `get_filename(self, queryset)` if a dynamic filename is required.
`specify_separator` - *boolean* - Default: `True`
Whether or not to include `sep=<sepaator>` as the first line of the CSV file. This is useful for generating Microsoft
Excel friendly CSV.
## Contributions
Pull requests are happily accepted.
## Alternatives
https://github.com/django-import-export/django-import-export/
https://github.com/mjumbewu/django-rest-framework-csv
A Django class-based view for CSV export.
[](https://travis-ci.org/benkonrath/django-csv-export-view)
## Features
* Easy CSV exports using the familiar `model` and `fields` / `exclude` pattern
* Works with your existing class-based view mixins for access control
* Generates Micosoft Excel friendly CSV by default
* Easy to override defaults as needed
* Proper HTTP headers set for CSV
## Quick Start
Examples:
```python
class DataExportView(CSVExportView):
model = Data
fields = ('field1', 'field2__related_field', 'property1')
class DataExportView(CSVExportView):
model = Data
fields = '__all__'
class DataExportView(CSVExportView):
exclude = ('id',)
def get_queryset(self):
queryset = super(DataExportView, self).get_queryset()
return queryset.filter(deleted=True)
```
`fields` / `exclude`: An interable of field names and properties. You cannot set both `fields` and `exclude`.
`fields` can also be `'__all__'` to export all fields. Model properties are not included when `'__all__'` is used.
Related field can be used with `__`.
`model`: The model to use for the CSV export queryset. Override `get_queryset()` if you need a custom queryset.
## Further Customization
Examples:
```python
class DataExportView(CSVExportView):
model = Data
fields = '__all__'
header = False
specify_separator = False
filename = 'data-export.csv'
class DataExportView(CSVExportView):
model = Data
fields = '__all__'
def get_filename(self, queryset):
return 'data-export-{!s}.csv'.format(timezone.now())
```
`header` - *boolean* - Default: `True`
Whether or not to include the header in the CSV.
`filename` - *string* - Default: Dasherized version of `verbose_name_plural` from `queryset.model`.
Override `get_filename(self, queryset)` if a dynamic filename is required.
`specify_separator` - *boolean* - Default: `True`
Whether or not to include `sep=<sepaator>` as the first line of the CSV file. This is useful for generating Microsoft
Excel friendly CSV.
## Contributions
Pull requests are happily accepted.
## Alternatives
https://github.com/django-import-export/django-import-export/
https://github.com/mjumbewu/django-rest-framework-csv
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file django-csv-export-view-0.1.0.tar.gz
.
File metadata
- Download URL: django-csv-export-view-0.1.0.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
e50bafa32d6f311382d71e9ae913927e571d5f00bd75551bc31fee8f551bf177
|
|
MD5 |
8a11757e1fc6df31482aa0362de872c2
|
|
BLAKE2b-256 |
f040ead4e338ec708858af1f11e51a96400bf38399b475b1bcbc2ba0e31f318b
|