Tweaked admin and models. Added filters to manage navigation display.
[philo.git] / contrib / navigation / admin.py
1 from django.contrib import admin
2 from philo.admin import TreeEntityAdmin, COLLAPSE_CLASSES, NodeAdmin
3 from philo.contrib.navigation.models import Navigation
4
5
6 NAVIGATION_RAW_ID_FIELDS = ('hosting_node', 'parent', 'target_node')
7
8
9 class NavigationInline(admin.StackedInline):
10         fieldsets = (
11                 (None, {
12                         'fields': ('text',)
13                 }),
14                 ('Target', {
15                         'fields': ('target_node', 'url_or_subpath',)
16                 }),
17                 ('Advanced', {
18                         'fields': ('reversing_parameters', 'order', 'depth'),
19                         'classes': COLLAPSE_CLASSES
20                 }),
21                 ('Expert', {
22                         'fields': ('hosting_node', 'parent'),
23                         'classes': COLLAPSE_CLASSES
24                 })
25         )
26         raw_id_fields = NAVIGATION_RAW_ID_FIELDS
27         model = Navigation
28         extra = 1
29         sortable_field_name = 'order'
30
31
32 class NavigationNavigationInline(NavigationInline):
33         verbose_name = "child"
34         verbose_name_plural = "children"
35
36
37 class NodeNavigationInline(NavigationInline):
38         verbose_name_plural = 'navigation'
39
40
41 class NavigationAdmin(TreeEntityAdmin):
42         list_display = ('__unicode__', 'target_node', 'url_or_subpath', 'reversing_parameters')
43         fieldsets = (
44                 (None, {
45                         'fields': ('text', 'hosting_node',)
46                 }),
47                 ('Target', {
48                         'fields': ('target_node', 'url_or_subpath',)
49                 }),
50                 ('Advanced', {
51                         'fields': ('reversing_parameters', 'depth'),
52                         'classes': COLLAPSE_CLASSES
53                 }),
54                 ('Expert', {
55                         'fields': ('parent', 'order'),
56                         'classes': COLLAPSE_CLASSES
57                 })
58         )
59         raw_id_fields = NAVIGATION_RAW_ID_FIELDS
60         inlines = [NavigationNavigationInline] + TreeEntityAdmin.inlines
61
62
63 NodeAdmin.inlines = [NodeNavigationInline] + NodeAdmin.inlines
64
65
66 admin.site.register(Navigation, NavigationAdmin)