A Django admin theme using Bootstrap. It doesn't need any kind of modification on your side, just add it to the installed apps.
- Django
>=1.6
Since 2.0
we are targeting Bootstrap 3 and recent Django versions.
The old 1.x
series works with Django >=1.4
and <1.7
.
- Download it from PyPi with
pip install django-admin-bootstrapped
- Add into the
INSTALLED_APPS
before'django.contrib.admin'
:
'django_admin_bootstrapped',
- Have fun!
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:
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:
With a version of django < 1.7
you can't change the application
name, but django-admin-bootstrapped let you do it in a really easy way.
Create a file named admin_app_name.html
into the application's
template folder. Eg: myapp/templates/admin_app_name.html
or
project/templates/myapp/admin_app_name.html
. Please be warned that
since this is already possible using plain django the feature
will be removed in favour of the upstream solution.
You can also change the default Django Administration title, just add a
admin_title.html
file into your project/templates/admin/
folder.
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
.
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. The result will look like this:
This feature was brought to you by Kyle Bock. Thank you Kyle!
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'
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!