mirror of
https://github.com/jazzband/django-admin2.git
synced 2026-03-17 06:30:25 +00:00
68 lines
1.9 KiB
Python
68 lines
1.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
from __future__ import division, absolute_import, unicode_literals
|
|
|
|
from django.contrib import messages
|
|
from django.utils.translation import ugettext_lazy
|
|
|
|
import djadmin2
|
|
from djadmin2 import renderers
|
|
from djadmin2.actions import DeleteSelectedAction
|
|
|
|
# Import your custom models
|
|
from .actions import CustomPublishAction, PublishAllItemsAction
|
|
from .models import Post, Comment
|
|
|
|
|
|
class CommentInline(djadmin2.Admin2TabularInline):
|
|
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')
|
|
|
|
|
|
def unpublish_all_items(request, queryset):
|
|
queryset.update(published=False)
|
|
messages.add_message(
|
|
request,
|
|
messages.INFO,
|
|
ugettext_lazy('Items unpublished'),
|
|
)
|
|
|
|
unpublish_all_items.description = ugettext_lazy('Unpublish all items')
|
|
unpublish_all_items.only_selected = False
|
|
|
|
|
|
class PostAdmin(djadmin2.ModelAdmin2):
|
|
list_actions = [
|
|
DeleteSelectedAction, CustomPublishAction,
|
|
PublishAllItemsAction, unpublish_items,
|
|
unpublish_all_items,
|
|
]
|
|
inlines = [CommentInline]
|
|
search_fields = ('title', '^body')
|
|
list_display = ('title', 'body', 'published', "published_date",)
|
|
field_renderers = {
|
|
'title': renderers.title_renderer,
|
|
}
|
|
save_on_top = True
|
|
date_hierarchy = "published_date"
|
|
ordering = ["-published_date", "title",]
|
|
|
|
|
|
class CommentAdmin(djadmin2.ModelAdmin2):
|
|
search_fields = ('body', '=post__title')
|
|
list_filter = ['post', ]
|
|
actions_on_top = True
|
|
actions_on_bottom = True
|
|
actions_selection_counter = False
|
|
|
|
|
|
# Register each model with the admin
|
|
djadmin2.default.register(Post, PostAdmin)
|
|
djadmin2.default.register(Comment, CommentAdmin)
|
|
|