Skip to main content

A Bootstrap theme for Django Admin

Project description

https://travis-ci.org/django-admin-bootstrapped/django-admin-bootstrapped.svg

PyPI version

A Django admin theme using Bootstrap. It doesn’t need any kind of modification on your side, just add it to the installed apps.

Requirements

  • Django >=2.0.6

Installation

  1. Download it from PyPi with pip install django-admin-bootstrapped

  2. Add into the INSTALLED_APPS before 'django.contrib.admin':

'django_admin_bootstrapped',
  1. Have fun!

Configuration

For a full bootstrap3 experience you may want to use a custom renderer for the fields. There’s one available in tree that requires the django-bootstrap3 application installed. You have to add to your project settings file:

DAB_FIELD_RENDERER = 'django_admin_bootstrapped.renderers.BootstrapFieldRenderer'

Messages will have alert-info tag by default, so you may want to add Bootstrap 3 tags for different message levels to make them styled appropriately. Add to your project settings file:

from django.contrib import messages

MESSAGE_TAGS = {
            messages.SUCCESS: 'alert-success success',
            messages.WARNING: 'alert-warning warning',
            messages.ERROR: 'alert-danger error'
}

Now, adding messages like this:

messages.success(request, "My success message")
messages.warning(request, "My warning message")
messages.error(request, "My error message")

will result into this:

https://i.imgur.com/SQNMZZE.png

Goodies

Add custom html to the change form of any model with a template

You can inject custom html on top of any change form creating a template named admin_model_MODELNAME_change_form.html into the application’s template folder. Eg: myapp/templates/myapp/admin_model_mymodelname_change_form.html or project/templates/myapp/admin_model_mymodelname_change_form.html.

Inline sortable

You can add drag&drop sorting capability to any inline with a couple of changes to your code.

First, add a position field in your model (and sort your model accordingly), for example:

class TestSortable(models.Model):
    that = models.ForeignKey(TestMe)
    position = models.PositiveSmallIntegerField("Position")
    test_char = models.CharField(max_length=5)

    class Meta:
        ordering = ('position', )

Then in your admin.py create a class to handle the inline using the django_admin_bootstrapped.admin.models.SortableInline mixin, like this:

from django_admin_bootstrapped.admin.models import SortableInline
from models import TestSortable

class TestSortable(admin.StackedInline, SortableInline):
    model = TestSortable
    extra = 0

You can now use the inline as usual. See the screenshots section to see what the result will look like.

This feature was brought to you by Kyle Bock. Thank you Kyle!

XHTML Compatible

Compatible with both html and xhtml. To enable xhtml for your django app add the following to your settings.py: DEFAULT_CONTENT_TYPE = ‘application/xhtml+xml’

Generic lookups in admin

All that needs to be done is change the admin widget with either formfield_overrides like this:

from django_admin_bootstrapped.widgets import GenericContentTypeSelect

class SomeModelAdmin(admin.ModelAdmin):
    formfield_overrides = {
        models.ForeignKey: {'widget': GenericContentTypeSelect},
    }

Or if you want to be more specific:

from django_admin_bootstrapped.widgets import GenericContentTypeSelect

class SomeModelAdmin(admin.ModelAdmin):
    def formfield_for_dbfield(self, db_field, **kwargs):
        if db_field.name == 'content_type':
            kwargs['widget'] = GenericContentTypeSelect
        return super(SomeModelAdmin, self).formfield_for_dbfield(db_field, **kwargs)

If you decide on using formfield_overrides you should be aware of its limitations with relation fields.

This feature (and many more) was brought to you by Jacob Magnusson. Thank you Jacob!

Contributing

Every code, documentation and UX contribution is welcome.

Found an issue? Report it in the bugtracker!

Have some free time? Help fixing an already filed issue, just remember to work on a separate branch please.

Screenshots

Homepage

https://cloud.githubusercontent.com/assets/12932/6967318/d7064abe-d95e-11e4-91bc-6de527550557.png

List view with filters in dropdown

https://cloud.githubusercontent.com/assets/12932/6967319/d71a9c6c-d95e-11e4-86cf-47e8857582c1.png

Change form view

https://cloud.githubusercontent.com/assets/12932/6966950/98661ba6-d95c-11e4-8bb3-e4b18759115b.png

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-bootstrapped-ivc-2.5.7.6.tar.gz (380.0 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file django-admin-bootstrapped-ivc-2.5.7.6.tar.gz.

File metadata

  • Download URL: django-admin-bootstrapped-ivc-2.5.7.6.tar.gz
  • Upload date:
  • Size: 380.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.7.0

File hashes

Hashes for django-admin-bootstrapped-ivc-2.5.7.6.tar.gz
Algorithm Hash digest
SHA256 9a4cd4a1136d0dddcc48005eafbfa2e36e749b114c8f88e3e2d6c0e26c24882e
MD5 4bd3f6f5aeffcc8fc20fc44d538c8812
BLAKE2b-256 8677fc6e35e3903b3fc27c87be06486d00495e52189302710ac7ddd9ec7d296a

See more details on using hashes here.

File details

Details for the file django_admin_bootstrapped_ivc-2.5.7.6-py3-none-any.whl.

File metadata

  • Download URL: django_admin_bootstrapped_ivc-2.5.7.6-py3-none-any.whl
  • Upload date:
  • Size: 403.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.7.0

File hashes

Hashes for django_admin_bootstrapped_ivc-2.5.7.6-py3-none-any.whl
Algorithm Hash digest
SHA256 5d58ae88b53ba4a050251c26b5e5d9805336b7aa78eb19357dbc5dd687fd0188
MD5 365d323beb783d7578a79da9eed2aad7
BLAKE2b-256 a06e9202ff42f8b9c08458b6777891365a6cc27b5192dc2fefda3bf0ac078189

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