A Bootstrap theme for Django Admin
Project description
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 1.11
Installation
Download it from PyPi with pip install tendenci-django-admin-bootstrapped
Add into the INSTALLED_APPS before 'django.contrib.admin':
'django_admin_bootstrapped',
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:
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
List view with filters in dropdown
Change form view
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
Built Distribution
File details
Details for the file tendenci-django-admin-bootstrapped-5.2.tar.gz
.
File metadata
- Download URL: tendenci-django-admin-bootstrapped-5.2.tar.gz
- Upload date:
- Size: 382.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.10.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 11421fa92ec687b62d8890c2a011ce07e913c43c7aab8dd178c81647b61eb0e5 |
|
MD5 | d8aabcefed89c384cf8f51a71dd48113 |
|
BLAKE2b-256 | bb44ade14a016e4b63fe337e9899c66b3615083ee4a33ae8eb32c6adb8d96960 |
File details
Details for the file tendenci_django_admin_bootstrapped-5.2-py3-none-any.whl
.
File metadata
- Download URL: tendenci_django_admin_bootstrapped-5.2-py3-none-any.whl
- Upload date:
- Size: 407.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.10.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a5a3494f8310effe273ea02182311ecfbf6b7ebb61e99f817237aea797a2e6b4 |
|
MD5 | a9165924372f8ee24054c1b40a6e2079 |
|
BLAKE2b-256 | a4a7a05cd878a9abef6f79b11b7e99602b4ec3712aa39a17a00e94690ee571b4 |