Skip to main content

Django Admin Export Action

Version Build status License Coverage

Export action for Django's Admin

Quickstart

Install Django Admin Export Action::

pip install django-admin-export-action

Include it in INSTALLED_APPS::

INSTALLED_APPS = [
    # ...
    'admin_export_action',
]

Add to urlpatterns in urls.py:

path('export_action/', include("admin_export_action.urls", namespace="admin_export_action")),

Configuration

By default the export action will be added sitewide, which means for every app and every admin registered model.

You can disable this behaviour and decide to add manually the export action only for the models you desired:

# settings.py

ADMIN_EXPORT_ACTION = {
    'ENABLE_SITEWIDE': False
}

# model admin
from admin_export_action.admin import export_selected_objects

class MyModelAdmin(models.ModelAdmin):
    # ...
    actions = [export_selected_objects, ]

Convert any value to its xlsx representation can be a nightmare, and you may always find something weird you haven't considered. In order to let you fix every case, you can define an hook which is called when adding a value to a cell:

# settings.py

ADMIN_EXPORT_ACTION = {
    'VALUE_TO_XLSX_CELL': 'news.admin.my_convert_function'
}

# admin.py
def my_convert_function(value):
    if (value == 'convert'):
        return True, 'converted'
    elif (type(value) == list):
        return json.dumps(value)
    return False, None

If called, the hook is called first, it shoud return a tuple success, value. If success is True, then the returned value is used, otherwise the default conversions are performed.

The intermediate admin page used to select the fields to be exported needs the extra context each admin page has. But such context depends on your admin_site instance, for example if you use django-baton the admin site is different from the default one. For this reason you can specify the path for your admin app:

# settings.py

ADMIN_EXPORT_ACTION = {
    'ADMIN_SITE_PATH': 'baton.autodiscover.admin'
}

This assures the site title and site header ar the ones you see in normal admin pages.

Usage

Go to an admin page where the export action is enabled, select objects, run the action.

In the next page:

  • select the fields you want to export
  • select the output format
  • select whether to get raw choices values or not
  • select whether to include table header (field verbose name) or not
  • click the "Export" button

Features

  • Generic or ready to use action to enable export data from Admin.
  • Automatic traversal of model relations.
  • Selection of fields to export.
  • Can export to XSLx, CSV, JSON and HTML.

Running Tests

Does the code actually work?

cd testapp/app
source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install -r requirements.txt
(myenv) $ python manage.py test

Security

This project assumes staff users are trusted. There may be ways for users to manipulate this project to get more data access than they should have.

Credits

This project is developed by Otto srl, and originally foked from fgmacedo/django-export-action

Metadata

Release files for django-admin-export-action 0.3.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-admin-export-action 0.3.3
File Size Uploaded Provenance Actions
django_admin_export_action-0.3.3.tar.gz 17.3 kB Without provenance Details for django_admin_export_action-0.3.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-admin-export-action 0.3.3
File Interpreter ABI Platform Actions
django_admin_export_action-0.3.3-py3-none-any.whl Python 3 none any Details for django_admin_export_action-0.3.3-py3-none-any.whl

Total release size: 40.6 kB

Release files / django_admin_export_action-0.3.3.tar.gz

Download URL django_admin_export_action-0.3.3.tar.gz
Size 17.3 kB
Tags Source
SHA-256 checksum
How to use checksums
80224e1bf7f81b8d7fa05ff3af5b638bc5833205c54009519eed35a89de1ad2a
BLAKE2b-256 checksum
How to use checksums
ce5dd51a09c5ca39c9708c6617983dcf19b20c1ee0851633c2f14a7d3ed03534
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.3

Release files / django_admin_export_action-0.3.3-py3-none-any.whl

Download URL django_admin_export_action-0.3.3-py3-none-any.whl
Size 23.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cc38b77970e12f4bc7dfcdbff288e0ca48a16e3d2e90da14e6cfe336a991fe8c
BLAKE2b-256 checksum
How to use checksums
44ff1dace23f319053380bc6f0d1e7e52adc85681dad72937d1d9d52df2a704d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.3

Security for django-admin-export-action 0.3.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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page