django-admin2/example/blog/admin2.py

39 lines
1.1 KiB
Python
Raw Normal View History

from django.contrib import messages
from django.utils.translation import ugettext_lazy
2013-05-31 15:38:34 +00:00
import djadmin2
from djadmin2.actions import DeleteSelectedAction
2013-07-06 16:33:44 +00:00
# Import your custom models
from .actions import CustomPublishAction
2013-05-31 15:38:34 +00:00
from .models import Post, Comment
class CommentInline(djadmin2.Admin2Inline):
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')
2013-07-07 09:34:06 +00:00
list_filter = ['published', 'title']
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', ]
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)