Skip to main content

A reusable Django package to add column toggle functionality in the Django admin interface.

Project description

Django Admin Column Toggle

Django Admin Column Toggle is a reusable Django package that adds column toggle functionality to the Django admin interface. This allows users to show or hide columns in the list view of the Django admin site.

Installation

  1. Install the package:

    With poetry

    poetry add django-admin-column-toggle
    

    With pip

    pip install django-admin-column-toggle
    
  2. Add 'column_toggle' to your `INSTALLED_APPS` setting in your Django project:

    INSTALLED_APPS = [
    ...
    'column_toggle',
    ]
    

Usage

  1. Import `ColumnToggleModelAdmin` from `column_toggle.admin` and inherit it in your `ModelAdmin` class. For example:

    from django.contrib import admin
    from column_toggle.admin import ColumnToggleModelAdmin
    from .models import YourModel
    
    @admin.register(YourModel)
    class YourModelAdmin(ColumnToggleModelAdmin):
        list_display = ('field1', 'field2', 'field3')
    
  2. To set the default selected columns, add the `default_selected_columns` attribute in your `ModelAdmin` class:

    @admin.register(YourModel)
    class YourModelAdmin(ColumnToggleModelAdmin):
        list_display = ('field1', 'field2', 'field3')
        default_selected_columns = ['field1', 'field2']
    

    By doing this, only the specified columns ('field1' and 'field2' in this example) will be visible by default. Users can still toggle the visibility of other columns manually.

  3. That's it! Now you should have column toggle functionality in the Django admin list view for the specified model.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

Project details


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_column_toggle-0.4.2.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file django_admin_column_toggle-0.4.2.tar.gz.

File metadata

  • Download URL: django_admin_column_toggle-0.4.2.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.6 Linux/6.10.10-arch1-1

File hashes

Hashes for django_admin_column_toggle-0.4.2.tar.gz
Algorithm Hash digest
SHA256 ffad9da0cc9d1173486430c3cb93075fed0cd24bde8c12e1653aeca2b3c2a279
MD5 b8a663da52880e7510a69ac5bb1cf063
BLAKE2b-256 15e7ef70ddf048d5b24612b8acc3db294d24aa0a6b46be7d1216c7b5832f3c72

See more details on using hashes here.

File details

Details for the file django_admin_column_toggle-0.4.2-py3-none-any.whl.

File metadata

File hashes

Hashes for django_admin_column_toggle-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 62eaba6842ae923dd6dbbcecb885200636590e49fa57fab61e015ac602cb46f1
MD5 f58f305fd5736fe6fa281aea506b743e
BLAKE2b-256 cf98fbe019014538f2d45e5bca68ba0364a401d23d29155d4d22c2f9c2cd59d0

See more details on using hashes here.

Supported by

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