django-admin2/example/blog/admin2.py

50 lines
1.3 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2013-07-07 14:13:48 +00:00
from __future__ import division, absolute_import, unicode_literals
from django.contrib import messages
from django.utils.translation import ugettext_lazy
2013-05-31 15:38:34 +00:00
import djadmin2
from djadmin2 import renderers
from djadmin2.actions import DeleteSelectedAction
2013-07-06 16:33:44 +00:00
# Import your custom models
from .actions import CustomPublishAction
2013-07-07 13:43:43 +00:00
from .models import Post, Comment
2013-05-31 15:38:34 +00:00
class CommentInline(djadmin2.Admin2TabularInline):
2013-05-19 09:21:25 +00:00
model = Comment
def unpublish_items(request, queryset):
queryset.update(published=False)
messages.add_message(request, messages.INFO, ugettext_lazy(u'Items unpublished'))
# Translators : action description
unpublish_items.description = ugettext_lazy('Unpublish selected items')
class PostAdmin(djadmin2.ModelAdmin2):
list_actions = [DeleteSelectedAction, CustomPublishAction, unpublish_items]
2013-05-19 09:21:25 +00:00
inlines = [CommentInline]
2013-06-06 21:25:36 +00:00
search_fields = ('title', '^body')
list_display = ('title', 'body', 'published')
2013-07-07 12:26:25 +00:00
field_renderers = {
'title': renderers.title_renderer,
}
2013-07-08 17:14:19 +00:00
save_on_top = True
2013-06-06 21:25:36 +00:00
2013-06-06 21:25:36 +00:00
class CommentAdmin(djadmin2.ModelAdmin2):
search_fields = ('body', '=post__title')
list_filter = ['post', ]
actions_on_top = True
actions_on_bottom = True
2013-05-19 09:21:25 +00:00
# Register each model with the admin
2013-05-19 09:21:25 +00:00
djadmin2.default.register(Post, PostAdmin)
2013-06-06 21:25:36 +00:00
djadmin2.default.register(Comment, CommentAdmin)
2013-07-07 13:43:43 +00:00