django-admin2/example/blog/admin2.py
Kevin Diale 29eaa661d5 Drilling down works on a functional level. Gotta set up interface and
tests.

On a related note, TAKE THAT DJANGO FILTERS.
2013-07-30 16:28:24 -04:00

51 lines
1.4 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.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')
class PostAdmin(djadmin2.ModelAdmin2):
list_actions = [DeleteSelectedAction, CustomPublishAction, unpublish_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"
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)