Django-admin-action to export items as csv-formatted data.
Project description
Description
Django-admin-csvexport is a django-admin-action, that allows you to export the items of your django-admin changelist as csv-formatted data.
Features
selectable model-fields
related models included
customizable csv-format
view or download csv-data
Installation
Install from pypi.org:
pip install django-admin-csvexport
Add csvexport to your installed apps:
INSTALLED_APPS = [ 'csvexport', ... ]
Add csvexport to the actions of your modeladmin:
from csvexport.actions import csvexport class MyModelAdmin(admin.ModelAdmin): ... actions = [csvexport]
Configuration
The following settings determine the depth of the model references and the value to display for empty fields:
CSV_EXPORT_REFERENCE_DEPTH = 3 CSV_EXPORT_EMPTY_VALUE = ''
The following settings define the csv-format to be used. The default values meet the unix standard csv-format:
CSV_EXPORT_DELIMITER = ',' CSV_EXPORT_ESCAPECHAR = '' CSV_EXPORT_QUOTECHAR = '"' CSV_EXPORT_DOUBLEQUOTE = True CSV_EXPORT_LINETERMINATOR = r'\n' CSV_EXPORT_QUOTING = 'QUOTE_ALL'
For the newline escape sequence use a raw-string.
For CSV_EXPORT_QUOTING
use the name of one of these csv module
constants:
The csv-format can also be adjusted by the formular rendered by the csvexport admin-action. If there is no need to adjust the csv-format on each export use:
CSV_EXPORT_FORMAT_FORM = False
The formular can also be extended by a checkbox which allows to filter the resulting csv rows to be unique. Therefore use:
CSV_EXPORT_UNIQUE_FORM = True
With the following additional parameters for your ModelAdmin you could limit the fields offered by the export form and choose them to be preselected:
class MyModelAdmin(admin.ModelAdmin): csvexport_export_fields = [ 'field_a', 'field_b, 'relational_field.field_a_on_related_model', ... ] csvexport_selected_fields = [ 'field_a', 'field_b, 'relational_field.field_a_on_related_model', ... ]
Fields of related models could be referenced by using a dot between the
relational fields and the fields to be exported:
'relation_a.relation_b.any_field'
. Not defining
csvexport_export_fields
means all possible fields will be regarded.
Usage
Just use it as any django-admin-action: Select your items, choose csvexport from the admin-action-bar and go. You will be led to a formular that allows you to view or download your items as csv-data.
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
Built Distribution
Hashes for django-admin-csvexport-1.9.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0170b9e1b9ba5f54f11cc2b77e43289cdd1a6a0d76fdcbb8270f519593f87be1 |
|
MD5 | 0752c39653392e2c459fc89c0b7ae3ee |
|
BLAKE2b-256 | 7d36ceebc1a09b97c30857d74e03ef2303ad1e00416f8d730505e84c43ae7c83 |
Hashes for django_admin_csvexport-1.9-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d44f20f29705f12e6715b9c07fdbaa5494bee518cf825e795a83808a758eeed5 |
|
MD5 | 9823be95274b24d4cab983e090593626 |
|
BLAKE2b-256 | 87415bf66b8e0ef96d2cbda738f892d3a4e68a55929db2c8bf4ca9f24badd213 |