mirror of
https://github.com/jazzband/django-admin2.git
synced 2026-03-17 06:30:25 +00:00
49 lines
1.3 KiB
Python
49 lines
1.3 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
|
|
from .models import Post, Comment
|
|
|
|
|
|
class CommentInline(djadmin2.Admin2Inline):
|
|
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]
|
|
inlines = [CommentInline]
|
|
search_fields = ('title', '^body')
|
|
list_display = ('title', 'body', 'published')
|
|
field_renderers = {
|
|
'title': renderers.title_renderer,
|
|
}
|
|
save_on_top = True
|
|
|
|
|
|
class CommentAdmin(djadmin2.ModelAdmin2):
|
|
search_fields = ('body', '=post__title')
|
|
list_filter = ['post', ]
|
|
actions_on_top = True
|
|
actions_on_bottom = True
|
|
|
|
|
|
# Register each model with the admin
|
|
djadmin2.default.register(Post, PostAdmin)
|
|
djadmin2.default.register(Comment, CommentAdmin)
|
|
|