Skip to main content

Base classes and mixins to facilitate toggling visibility between multiple Django admin fields.

Project description

Django Toggled Widgets

This package makes it possible to toggle between fields in the Django admin. When a form containing toggled fields is submitted, any field that did not have visibility upon submission is automatically set empty in the cleaned data.

Usage

  1. Add "toggled_widgets" to your `INSTALLED_APPS setting.

  2. Add toggled_widgets.ToggledWidgetFormMixin to the MRO of any form class that requires the toggle behavior.

  3. Set the form class' toggle_groups attribute to an iterable of tuples that describe the toggle relationship.

  4. Add `toggled_widgets.ToggledWidgetAdminMixin to the MRO of any model admin class that uses a form containing the toggle behavior.

  5. Optionally add toggled_widgets.ToggledWidgetMixin to the MRO of the toggled widget classes in order to gain more control over the appearance of the toggle control (e.g. by defining the metafield_label to customize the toggle control's label).

ModelForm configuration

In the simplest implementation, each element in the tuples contained in the form class' toggle_groups attribute is a string whose value is a field name. The admin form will provide a control to toggle between these fields. For example:

class SomeModelForm(ToggledWidgetFormMixin, ModelForm):
    toggle_groups = [
        ('some_field', 'some_other_field')
    ]

Any element in the tuple may also be an iterable containing multiple field names. In this case, any field name past the first in this iterable will toggle sympathetically along with the field named in the first item.

class SomeModelForm(ToggledWidgetFormMixin, ModelForm):
    toggle_groups = [
        ('some_field', ('some_other_field', 'some_third_field'))
    ]

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-toggled-widgets-0.8.tar.gz (21.4 kB view details)

Uploaded Source

Built Distribution

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

django_toggled_widgets-0.8-py3-none-any.whl (22.5 kB view details)

Uploaded Python 3

File details

Details for the file django-toggled-widgets-0.8.tar.gz.

File metadata

  • Download URL: django-toggled-widgets-0.8.tar.gz
  • Upload date:
  • Size: 21.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.13

File hashes

Hashes for django-toggled-widgets-0.8.tar.gz
Algorithm Hash digest
SHA256 780b82fd18a6c1d8e4341be15698d45f074ffc410a679469efe1d18c85434242
MD5 3d817a4078656993118af1b17727b3f5
BLAKE2b-256 56b32fd1783ad7f02a04d7b4c53b9112db1a4cf9623e89b720c087ec6532a669

See more details on using hashes here.

File details

Details for the file django_toggled_widgets-0.8-py3-none-any.whl.

File metadata

  • Download URL: django_toggled_widgets-0.8-py3-none-any.whl
  • Upload date:
  • Size: 22.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.13

File hashes

Hashes for django_toggled_widgets-0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 403fb71aa12ea08f7e84a85c2dc29811749bff9cd63e0353bbe87d1e8f5d9a1c
MD5 32dd95f7cb7af29c56e25ca0b73195cc
BLAKE2b-256 55326bc541b7ed605fd9aefd7aebe71c916e8c37117a0f3d317ded97f278fa57

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