19.5. Django Grappelli
As of April 2024 this app is no longer maintained
19.5.1. Install
Run in the system terminal:
$ python -m pip install django-grappelli
Add to myproject/settings.py
:
INSTALLED_APPS += ['grappelli.dashboard', 'grappelli']
Add to myproject/urls.py
:
from django.conf.urls import url
from django.conf.urls import include
from django.contrib import admin
urlpatterns += [
url(r'^grappelli/', include('grappelli.urls'), name='grappelli'),
url(r'^', admin.site.urls, name='admin'),
]
19.5.2. Settings
Add to myproject/settings.py
:
GRAPPELLI_SWITCH_USER = True
GRAPPELLI_ADMIN_TITLE = _('My Project')
GRAPPELLI_AUTOCOMPLETE_SEARCH_FIELDS = {
'auth': {
'user': ['username__icontains']
}
}
19.5.3. Dashboard
Add to myproject/settings.py
:
GRAPPELLI_INDEX_DASHBOARD = 'myproject.dashboard.AdminDashboard'
Add to myproject/dashboard.py
:
from django.utils.translation import gettext_lazy as _
from grappelli.dashboard import Dashboard
from grappelli.dashboard import modules
class AdminDashboard(Dashboard):
def init_with_context(self, context):
# Column 1
self.children.append(modules.ModelList(
title=_('Questionnaires - Visible only to you'),
column=1,
collapsible=False,
models=[
'myproject.reporting.models.mood.Mood',
'myproject.reporting.models.sociodynamics.SociodynamicReport',
'myproject.reporting.models.sleep.Sleep']))
self.children.append(modules.ModelList(
title=_('Health - Visible only to you'),
column=1,
collapsible=False,
models=[
'myproject.health.models.blood_pressure.BloodPressure',
'myproject.health.models.urine.Urine',
'myproject.health.models.temperature.Temperature',
'myproject.health.models.weight.Weight']))
# Column 2
self.children.append(modules.ModelList(
title=_('Communication'),
column=2,
collapsible=False,
models=[
'myproject.communication.models.email.Email']))
self.children.append(modules.ModelList(
title=_('Reporting - Visible to anyone'),
column=2,
collapsible=False,
models=[
'myproject.reporting.models.daily.Daily',
'myproject.reporting.models.repair.Repair',
'myproject.reporting.models.incident.Incident',
'myproject.reporting.models.waste.Waste',
'myproject.communication.models.diary.DiaryEntry',
'myproject.extravehicular.models.activity.Activity']))
self.children.append(modules.ModelList(
title=_('Water - Visible to anyone'),
column=2,
collapsible=False,
models=[
'myproject.water.models.technical.TechnicalWater',
'myproject.water.models.drinking.DrinkingWater',
'myproject.water.models.green.GreenWater']))
# Column 3
if context['user'].has_perm('admin.add_user'):
self.children.append(modules.ModelList(
title=_('Administration'),
column=3,
collapsible=True,
models=['django.contrib.*'],
css_classes=['grp-closed']))
self.children.append(modules.LinkList(
title=_('Shortcuts'),
collapsible=False,
column=3,
children=[
{'title': _('Schedule'), 'url': '/api/v1/dashboard/schedule/'},
{'title': _('Martian Clock Converter'), 'url': '/api/v1/timezone/martian-standard-time/converter/'},
{'title': _('Subjective Time Perception'), 'url': 'http://time.astrotech.io'},
]))
self.children.append(modules.ModelList(
title=_('Sensors'),
column=3,
collapsible=False,
models=[
'myproject.sensors.models.zwave_sensor.ZWaveSensor']))
19.5.4. Template overwrite
change_list_template = 'admin/change_list_import_export.html'
change_list_filter_template = 'admin/filter_listing.html'