Skip to main content

Django-admin-action to export items as csv-formatted data.

Project description

Run tests for django-admin-csvexport coveralls badge python: 3.8, 3.9, 3.9, 3.10, 3.11, 3.12, 3.13 django: 2.2, 3.0, 3.1, 3.2, 4.0, 4.1, 4.2, 5.0, 5.1, 5.2, 6.0

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.

The CSV_EXPORT_REFERENCE_DEPTH value could also be adjusted in modeladmin specific manner:

class MyModelAdmin(admin.ModelAdmin):
    csvexport_reference_depth = 2

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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_admin_csvexport-2.4.0.tar.gz (18.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_admin_csvexport-2.4.0-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file django_admin_csvexport-2.4.0.tar.gz.

File metadata

  • Download URL: django_admin_csvexport-2.4.0.tar.gz
  • Upload date:
  • Size: 18.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for django_admin_csvexport-2.4.0.tar.gz
Algorithm Hash digest
SHA256 b582afc83589eca7462ac01de830dd68a7ec2cafaa77e43b334c18eef577eb46
MD5 f2f270c3249abdb5aefc19cc9f2440ac
BLAKE2b-256 634214f8d05f1abe82a0b73151793c0a6467bc7ff7711c95baee0deb97327fb7

See more details on using hashes here.

File details

Details for the file django_admin_csvexport-2.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_admin_csvexport-2.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 af499b79b15b12d5841d0ce5bde16407a1ed8857121a0318a64d938118770847
MD5 2ac6f99b4aa0e35a5fd86cc19a10e996
BLAKE2b-256 7e554c6c9919cb0b8da9c2851f10b4e265f7bac5a1d087b2d4530a27ccf77cd6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page