2013-07-07 09:48:59 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2013-07-07 14:13:48 +00:00
|
|
|
from __future__ import division, absolute_import, unicode_literals
|
2013-07-07 14:46:59 +00:00
|
|
|
|
2013-06-14 13:58:27 +00:00
|
|
|
from django.contrib import messages
|
2013-07-07 08:15:22 +00:00
|
|
|
from django.utils.translation import ugettext_lazy
|
2013-05-31 15:38:34 +00:00
|
|
|
|
2013-05-18 13:43:44 +00:00
|
|
|
import djadmin2
|
2013-07-07 09:48:59 +00:00
|
|
|
from djadmin2 import renderers
|
2013-06-14 13:58:27 +00:00
|
|
|
from djadmin2.actions import DeleteSelectedAction
|
2013-07-06 14:09:03 +00:00
|
|
|
|
2013-07-06 16:33:44 +00:00
|
|
|
# Import your custom models
|
2013-06-14 13:58:27 +00:00
|
|
|
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
|
|
|
|
2013-05-19 13:32:51 +00:00
|
|
|
|
2013-07-18 13:02:07 +00:00
|
|
|
class CommentInline(djadmin2.Admin2TabularInline):
|
2013-05-19 09:21:25 +00:00
|
|
|
model = Comment
|
|
|
|
|
|
|
|
|
|
|
2013-06-14 13:58:27 +00:00
|
|
|
def unpublish_items(request, queryset):
|
|
|
|
|
queryset.update(published=False)
|
2013-07-07 08:15:22 +00:00
|
|
|
messages.add_message(request, messages.INFO, ugettext_lazy(u'Items unpublished'))
|
2013-06-14 13:58:27 +00:00
|
|
|
|
2013-07-07 08:15:22 +00:00
|
|
|
# Translators : action description
|
|
|
|
|
unpublish_items.description = ugettext_lazy('Unpublish selected items')
|
2013-06-14 13:58:27 +00:00
|
|
|
|
|
|
|
|
|
2013-05-31 06:57:25 +00:00
|
|
|
class PostAdmin(djadmin2.ModelAdmin2):
|
2013-06-14 13:58:27 +00:00
|
|
|
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:48:59 +00:00
|
|
|
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-14 13:58:27 +00:00
|
|
|
|
2013-06-06 21:25:36 +00:00
|
|
|
class CommentAdmin(djadmin2.ModelAdmin2):
|
|
|
|
|
search_fields = ('body', '=post__title')
|
2013-07-06 14:09:03 +00:00
|
|
|
list_filter = ['post', ]
|
2013-07-07 14:46:59 +00:00
|
|
|
actions_on_top = True
|
|
|
|
|
actions_on_bottom = True
|
2013-05-19 09:21:25 +00:00
|
|
|
|
|
|
|
|
|
2013-05-18 13:43:44 +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
|
|
|
|