Skip to main content

Display toggle switch in stead of checkbox for BooleanField in django admin site.

Project description

django-toggle-switch-widget

Display toggle switch in stead of checkbox for BooleanField in django admin site.

Install

pip install django-toggle-switch-widget

Widget init parameters

  • attrs: Inherit from CheckboxInput.
  • check_test: Inherit from CheckboxInput.
  • round: Default to False. If round=True, display round switch. If round=False, display squire switch.
  • klass: Default to empty string "". Pre-setted klass are:
    • django-toggle-switch-success: Show success color (green, #06ad3d) while toggle on.
    • django-toggle-switch-warning: Show warning color (orange, #ff6a00) while toggle on.
    • django-toggle-switch-danger: Show danger color (red, #ba2121) while toggle on.
    • django-toggle-switch-dark-primary: Show dark primary color (darkcyan, #417690) while toggle on.
    • django-toggle-switch-primary: Show primary color (cadetblue, #79aec8) while toggle on.

Usage

pro/settings.py

INSTALLED_APPS = [
    ...
    'django_toggle_switch_widget',
    ...
]

app/model.py

from django.db import models

class TestModel(models.Model):
    title = models.CharField(max_length=64, help_text="Please input model title.")
    published = models.BooleanField(verbose_name="Is this test model published.")
    is_demo = models.BooleanField(help_text="Is this a demo test model?")

app/admin.py

from django.contrib import admin
from django.forms import ModelForm
from django_toggle_switch_widget.widgets import DjangoToggleSwitchWidget
from .models import TestModel

class TestModelForm(ModelForm):
    class Meta:
        model = TestModel
        exclude = []
        widgets = {
            "published": DjangoToggleSwitchWidget(klass="django-toggle-switch-dark-primary"),
            "is_demo": DjangoToggleSwitchWidget(round=True, klass="django-toggle-switch-success"),
        }

class TestModeldmin(admin.ModelAdmin):
    form = TestModelForm

admin.site.register(TestModel, TestModeldmin)

Tips

  • It's better to use together with django-checkbox-normalize app.

Release

v0.1.0 2020/03/02

  • First release.

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-toggle-switch-widget-0.1.0.tar.gz (5.4 kB view details)

Uploaded Source

File details

Details for the file django-toggle-switch-widget-0.1.0.tar.gz.

File metadata

  • Download URL: django-toggle-switch-widget-0.1.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.2

File hashes

Hashes for django-toggle-switch-widget-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d02bf723e8a52dc1414f08e50529d994682f03c82040bf6c89dfb701d05b479d
MD5 a74f98e0e6c01dc0b249c509748ce451
BLAKE2b-256 a69c0aeccacfa11af00c45fd1bec6f404f7251381427c29fd5a9f6d17d48d666

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