1
"""CategoryAdmin for Zinnia"""
2
from django.contrib import admin
3
from django.core.urlresolvers import NoReverseMatch
4
from django.utils.translation import ugettext_lazy as _
6
from zinnia.admin.forms import CategoryAdminForm
9
class CategoryAdmin(admin.ModelAdmin):
10
"""Admin for Category model"""
11
form = CategoryAdminForm
12
fields = ('title', 'parent', 'description', 'slug')
13
list_display = ('title', 'slug', 'get_tree_path', 'description')
14
prepopulated_fields = {'slug': ('title', )}
15
search_fields = ('title', 'description')
16
list_filter = ('parent',)
18
def __init__(self, model, admin_site):
19
self.form.admin_site = admin_site
20
super(CategoryAdmin, self).__init__(model, admin_site)
22
def get_tree_path(self, category):
23
"""Return the category's tree path in HTML"""
25
return '<a href="%s" target="blank">/%s/</a>' % \
26
(category.get_absolute_url(), category.tree_path)
27
except NoReverseMatch:
28
return '/%s/' % category.tree_path
29
get_tree_path.allow_tags = True
30
get_tree_path.short_description = _('tree path')