1 from django.contrib import admin
3 from philo.admin import TreeEntityAdmin, COLLAPSE_CLASSES, NodeAdmin, EntityAdmin
4 from philo.models import Node
5 from philo.contrib.shipherd.models import NavigationItem, Navigation
8 NAVIGATION_RAW_ID_FIELDS = ('navigation', 'parent', 'target_node')
11 class NavigationItemInline(admin.StackedInline):
12 raw_id_fields = NAVIGATION_RAW_ID_FIELDS
13 model = NavigationItem
15 sortable_field_name = 'order'
17 related_lookup_fields = {'fk': raw_id_fields}
20 class NavigationItemChildInline(NavigationItemInline):
21 verbose_name = "child"
22 verbose_name_plural = "children"
25 'fields': ('text', 'parent')
28 'fields': ('target_node', 'url_or_subpath',)
31 'fields': ('reversing_parameters', 'order'),
32 'classes': COLLAPSE_CLASSES
37 class NavigationNavigationItemInline(NavigationItemInline):
40 'fields': ('text', 'navigation')
43 'fields': ('target_node', 'url_or_subpath',)
46 'fields': ('reversing_parameters', 'order'),
47 'classes': COLLAPSE_CLASSES
52 class NodeNavigationItemInline(NavigationItemInline):
53 verbose_name_plural = 'targeting navigation'
59 'fields': ('target_node', 'url_or_subpath',)
62 'fields': ('reversing_parameters', 'order'),
63 'classes': COLLAPSE_CLASSES
66 'fields': ('parent', 'navigation')
71 class NodeNavigationInline(admin.TabularInline):
76 NodeAdmin.inlines = [NodeNavigationInline, NodeNavigationItemInline] + NodeAdmin.inlines
79 class NavigationItemAdmin(TreeEntityAdmin):
80 list_display = ('__unicode__', 'target_node', 'url_or_subpath', 'reversing_parameters')
83 'fields': ('text', 'navigation',)
86 'fields': ('target_node', 'url_or_subpath',)
89 'fields': ('reversing_parameters',),
90 'classes': COLLAPSE_CLASSES
93 'fields': ('parent', 'order'),
94 'classes': COLLAPSE_CLASSES
97 raw_id_fields = NAVIGATION_RAW_ID_FIELDS
98 related_lookup_fields = {'fk': raw_id_fields}
99 inlines = [NavigationItemChildInline] + TreeEntityAdmin.inlines
102 class NavigationAdmin(EntityAdmin):
103 inlines = [NavigationNavigationItemInline]
104 raw_id_fields = ['node']
105 related_lookup_fields = {'fk': raw_id_fields}
108 admin.site.unregister(Node)
109 admin.site.register(Node, NodeAdmin)
110 admin.site.register(Navigation, NavigationAdmin)
111 admin.site.register(NavigationItem, NavigationItemAdmin)