The powerful abstractions of iommi enable us to build an admin interface that is automagically created based on your models, while retaining the full feature set of iommi.
Editing an album:
Delete page for an album:
First declare a subclass of
from iommi.admin import Admin class MyAdmin(Admin): pass
This is the place you will put global configuration. If you don’t need any you can skip this step. Next plug it into your urls:
urlpatterns = [ # ... path('iommi-admin/', include(MyAdmin.urls())), ]
Now you have the iommi admin gui for your app!
Add a model to the admin#
You can add an app to your admin from your global config like this:
class MyAdmin(Admin): class Meta: apps__myapp_mymodel__include = True
This is especially useful for adding config to a third party app that doesn’t have built in iommi admin configuration.
You can also add the config in the app, by creating a
iommi_admin.py file in your app, and putting the configuration there:
class Meta: apps__myapp_mymodel__include = True
Remove a model from the admin#
By default iommi displays the built in Django
Group models. You can override this like:
class MyAdmin(Admin): class Meta: apps__auth_user__include = False
This turns off the admin of the
User table in the
auth app. Your global config always has priority.
By default staff users have access to the admin. You can change this by
from iommi.admin import Admin class MyAdmin(Admin): @staticmethod def has_permission(request, operation, model=None, instance=None): # This is the default implementation return request.user.is_staff
operation is one of
model parameter will be given for create/edit/delete/list, and instance will
be supplied in edit/delete.
You can configure attributes in the admin similarly to the rest of iommi, on
class MyAdmin(Admin): class Meta: parts__list_docs_album__columns__name__header__attrs__style__background = 'yellow'
The easiest way to find the path for configuration is to have
settings.IOMMI_DEBUG turned on (by default on if
DEBUG is on), and use
the pick feature and click on the element. You’ll get the path and also
the type so you can click your way to the documentation for that class.
In the example above the
data-iommi-path would be
Cell. In the docs for
Cell you can find that cells have