|
DocumentationDev
NOTE: This document is for grappelli's development version, which can be significantly different from previous releases. Changelog
RequirementsNOTE: grappelli DEV works with the newest release and/or repository checkout of these projects. InstallationBefore Installing Grappelli, please take a look at the known Django Issues.
Install Grappelli anywhere on your python-path. via svn:svn checkout http://django-grappelli.googlecode.com/svn/trunk/grappelli Open your projects settings-file (settings.py) and add Grappelli to your INSTALLED APPS before django.contrib.admin.
Add missing processors:
Add Grappelli to your url-definitions.
Copy the folder /media/ to your admin media-directory. Alternatively, you might want to use a symlink.cp -R /path/to/grappelli/media /path/to/your/admin/mediaNote: If possible, avoid using /django/contrib/admin/media/ as your media directory (since it will break future django-updates). python manage.py runserver localhost:8000 --adminmedia=/path/to/your/admin/media/ Grappelli SettingsAll Settings can be defined in your projects settings-file (settings.py). All grappelli settings use the prefix "GRAPPELLI_" (e.g. GRAPPELLI_ADMIN_TITLE instead of ADMIN_TITLE). Available Settings
Usage exampleGRAPPELLI_ADMIN_TITLE = 'My Application' Grappelli is used to ensure any settings found in the main settings.py file take precedence over the Grappelli's settings file and provide a default value if none is found. Visual Generic RelationsIn order to use Visual Generic Relations, you have to use the names content_type and object_id for defining generic relations. Making Generic Relations work/look like ForeignKeys: When editing a Generic Relation, you first choose the Content Type and then the Object-ID. With Grappelli, you instantly get the related object displayed right near the Object-ID. Note: You have to use names which include "content_type" and "object_id" for this to work. For example, your Model could look like this: from django.contrib.contenttypes import generic
from django.contrib.contenttypes.models import ContentType
from django.db import models
class ContainerItem(models.Model):
# ...
content_type = models.ForeignKey(ContentType, blank=True, null=True, related_name="content_type")
object_id = models.PositiveIntegerField(blank=True, null=True)
content_object = generic.GenericForeignKey("content_type", "object_id")
# ...
content_type_2 = models.ForeignKey(ContentType, blank=True, null=True, related_name="content_type_2")
object_id_2 = models.PositiveIntegerField(blank=True, null=True)
content_object_2 = generic.GenericForeignKey("content_type_2", "object_id_2")
Thanks to Weston Nielson (http://code.google.com/p/django-genericadmin/) for his inspiration. ModelAdmin OptionsWith Grappelli, you get some additional attributes for defining your ModelAdmin. Related LookupsWhen entering a value (ID) for a ForeignKey, the related object is instantly displayed right beside the input-field (after the search-icon).
This also works for a M2M-field.
Usagemodel.pyclass MyModel(models.Model):
related = models.ForeignKey(RelatedModel, verbose_name=u"Related Lookup", null=True, blank=True)
# ...admin.pyclass MyModelAdmin(admin.ModelAdmin):
list_display = ('__unicode__',)
raw_id_fields = ('related',)
# ...collapse open/closed
There are two classes for displaying fieldsets in the Admin-Interface. With "collapse open", the headline of the fieldset is collapsible and open by default. With "collapse closed", the headline of the fieldset is collapsible but closed by default. Without using a class, the fieldset won´t be collapsible. class EntryOptions(admin.ModelAdmin):
...
fieldsets = (
('', {
'fields': ('title', 'subtitle', 'slug', 'pub_date', 'status',),
}),
('Flags', {
'classes': ('collapse closed',),
'fields' : ('flag_front', 'flag_sticky', 'flag_allow_comments', 'flag_comments_closed',),
}),
('Tags', {
'classes': ('collapse closed',),
'fields' : ('tags',),
}),
('Image', {
'fields' : ('image',),
}),
('Content', {
'classes': ('collapse open',),
'fields' : ('summary', 'body',),
}),
('Author', {
'classes': ('collapse closed',),
'fields' : ('author',),
}),
)
class Media:
...search_fields_verboseIn order to actually see what you´re searching for within a Change-List, you can define search_fields_verbose. class EntryOptions(admin.ModelAdmin):
...
search_fields = ['id', 'title', 'subtitle', 'pub_date']
search_fields_verbose = ['ID', 'Title', 'Subtitle', 'Publication Date']
...actionscsv_export_selectedExport change_list as csv. from grappelli.actions import csv_export_selected
...
class EntryOptions(admin.ModelAdmin):
...
actions = [csv_export_selected]
...InlineModelAdmin Optionscollapse open/closed
There are two options for displaying inline-groups. With "collapse open", the inline-group is collapsible and open by default. With "collapse closed", the inline-group is collapsible but closed by default. Without using a class, the inline-group won´t be collapsible. class NavigationItemInline(admin.StackedInline):
classes = ('collapse open',)
...sortable inlinesYou can make inlines sortable (drag/drop) using a position field (i.e. PositiveSmallIntegerField) and an additional property with admin.StackedInline or admin.TabularInline. The field specified in the sortable_field_name will be hidden in the change_form. #model.py
class TabularOne(models.Model):
...
# position field
position = models.PositiveSmallIntegerField("Position")
class Meta:
ordering = ['position']
...
#admin.py
class TabularOne(admin.TabularInline):
...
# define the sortable
sortable_field_name = "position"
...Using TinyMCE
Copy tinymce_setup.js (in order to not break future updates) and adjust the setup/behaviour of TinyMCE according to your needs - see http://wiki.moxiecode.com/index.php/TinyMCE:Configuration class Media:
js = ['/media/admin/tinymce/jscripts/tiny_mce/tiny_mce.js', '/path/to/your/tinymce_setup.js',]
Multiple Admin SitesNote: deprecated docu! this part need a rework. If you need multiple Admin-Sites, you have to use Grappellis Admin-Site subclass. from grappelli.admin import AdminSite class MyModelAdmin(admin.ModelAdmin): ... my_admin_site = AdminSite(title="My Admin Site") my_admin_site.register(MyModel, MyModelAdmin) You need to change your url-patterns as well (of course): from django.conf.urls.defaults import *
from django.contrib import admin
admin.autodiscover()
from myapp.admin import my_admin_site
urlpatterns = patterns('',
(r'^admin/doc/', include('django.contrib.admindocs.urls')),
(r'^admin/filebrowser/', include('filebrowser.urls')),
(r'^grappelli/', include('grappelli.urls')),
(r'^admin/', include(admin.site.urls)),
(r'^my/admin/', include(my_admin_site.urls)),
...
grappelli + admin-toolsGrappelli is not only a skin for django.contrib.admin. It is a skin for django-admin-tools too. Thus grappelli has it's old bookmarks feature back. Additionally you can customize the order and hierarchy of the admin index and app_index, add modules like Recent Actions, Link List, and some more very nice features from admin-tools. Basically it works like described in the django-admin-tools docu but some things are different because of the different UI. DashboardModule.css_classesRequired
Optional
#poject's/dashboard.py
class CustomIndexDashboard(Dashboard):
def __init__(self, **kwargs):
Dashboard.__init__(self, **kwargs)
self.children.append(modules.LinkList(
title=_('Media Management'),
css_classes=['column_1'],
children=[
{
'title': _('Django FileBrowser'),
'url': '/admin/filebrowser/browse/',
'external': False,
'description': 'Python programming language rocks !',
},
]
))
self.children.append(modules.AppList(
title=_('User...'),
models=('django.contrib.auth.models.User',),
css_classes=['column_1', 'open'],
))
self.children.append(modules.AppList(
title=_('Administration'),
include_list=('django.contrib',),
css_classes=['column_1', 'closed'],
))
self.children.append(modules.AppList(
title=_('Administration'),
exclude_list=('django.contrib',),
css_classes=['column_1', 'closed'],
))
...
| |||||||