`django-export-download` allows you to use your ListView to download it in different file formats
like CSV or XLS by just adding the Mixin.
It provides a MultipleObject/ListView Mixin for Django. By passing the `download` GET parameter you can
download the file.
You can use this view to download the object list in different file fomats like CSV, XLS and more.
You just have to provide a `Resource` class from `django-import-export`.
I addition it work very good in you `django-tables2`/`django-filter` environment.
Finally the package ships with a templatetag to include some download buttons in your ListView template.
# Requirements
The package is tested with following versions, but it also should
work with newer or older versions
* Django >= 1.11
* django-import-export >= 1.0.0
* Python >= 3.5
# Quickstart
```python
views.py:
from import_export import resources
from export_download.views import ResourceDownloadMixin
from django.views.generic import ListView
class MovieBudgetResource(resources.ModelResource):
class Meta:
model = Movie
fields = ['title', 'budget']
class MovieListView(ResourceDownloadMixin, ListView):
model = Movie
resource_class = MovieBudget
urls.py:
urlpatterns = [
path('movie/', MovieListView.as_view(), name='movie-list'),
]
```
By visiting http://localhost:8000/movie/?download you can download a CSV (which is the default) file with the movies
and their budget.
```http://localhost:8000/movie/?download&resource_format=xls will download a Excel file.```
# Dokumentation
## Class Options
Here is a more complex example that includes several `Resources` and different file formats.
It also is a example how to use `django-export-download` with `django-filter` and `django-tables2`.
```python
import django_tables2 as table
from import_export import resources
from export_download.views import ResourceDownloadMixin
from django.views.generic import ListView
class MovieResource(resources.ModelResource):
class Meta:
model = Movie
fields = ['title', 'budget', 'tatus', 'votes', 'release_date']
class OnlyMovieResource(resources.ModelResource):
class Meta:
model = Movie
fields = ['title']
class MovieBudgetResource(resources.ModelResource):
class Meta:
model = Movie
fields = ['title', 'budget']
class MovieListView(ResourceDownloadMixin, ListView, table.SingleTableMixin):
model = Movie
table_class = MovieTable
filter_class = MovieFilter
resource_class = [
MovieResource,
OnlyMovieResource,
MovieBudgetResource
]
resource_formats = ['csv', 'tsv', 'xls']
```
This implementation support 3 download formats with 3 different `Resources`. Following URLs are giving
you the files:
```
http://localhost:8000/movie/?download&resource_class=0&resource_format=xls
http://localhost:8000/movie/?download&resource_class=0&resource_format=csv
http://localhost:8000/movie/?download&resource_class=0&resource_format=tsv
http://localhost:8000/movie/?download&resource_class=1&resource_format=xls
http://localhost:8000/movie/?download&resource_class=1&resource_format=csv
http://localhost:8000/movie/?download&resource_class=1&resource_format=tsv
http://localhost:8000/movie/?download&resource_class=2&resource_format=xls
http://localhost:8000/movie/?download&resource_class=2&resource_format=csv
http://localhost:8000/movie/?download&resource_class=2&resource_format=tsv
```
Note that `resource_class` defines the position of the `Resource` implementation in the list of `resource_class`
In this example there also is a `filter_class`. `django-export-download` automatically applies the filter
to the queryset. It is not required, but works really well. Have a look at https://github.com/carltongibson/django-filter
for more information.
## Templatetags
`django-export-download` ships with a templatetag to render all links above.
You now can use the templatetag in you ListView
```html
{% load export_download %}
{% resource_download_menu %}
```
# Contribute
Fork and send a PR
Metadata
Release files for django-export-download 0.2.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-export-download-0.2.3.tar.gz | 5.0 kB | Without provenance | Details for django-export-download-0.2.3.tar.gz |
Release files / django-export-download-0.2.3.tar.gz
| Download URL | django-export-download-0.2.3.tar.gz |
|---|---|
| Size | 5.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
decc0c7e180c152e1739bf15ae4f13c5422d3cd5ed9c014f0536b39a94f99990
|
|
BLAKE2b-256 checksum How to use checksums |
1145388a99b60d31ba01245bcd17ec99e464f1cb799933cab42e77116b1b3c6c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.10.0 pkginfo/1.2.1 requests/2.18.4 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.19.5 CPython/3.6.5
|
Security for django-export-download 0.2.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.