django-admin2/example/blog/admin2.py

53 lines
1.4 KiB
Python
Raw Permalink Normal View History

from django.utils.translation import gettext_lazy
2013-05-31 15:38:34 +00:00
from djadmin2 import renderers
from djadmin2.actions import DeleteSelectedAction
2013-07-06 16:33:44 +00:00
# Import your custom models
from djadmin2.site import djadmin2_site
from djadmin2.types import Admin2TabularInline, ModelAdmin2
from .actions import (CustomPublishAction, PublishAllItemsAction,
unpublish_items, unpublish_all_items)
2013-07-07 13:43:43 +00:00
from .models import Post, Comment
2013-05-31 15:38:34 +00:00
class CommentInline(Admin2TabularInline):
2013-05-19 09:21:25 +00:00
model = Comment
class PostAdmin(ModelAdmin2):
list_actions = [
DeleteSelectedAction, CustomPublishAction,
PublishAllItemsAction, unpublish_items,
unpublish_all_items,
]
2013-05-19 09:21:25 +00:00
inlines = [CommentInline]
2013-06-06 21:25:36 +00:00
search_fields = ('title', '^body')
list_display = ('title', 'body', 'published', "published_date",)
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
date_hierarchy = "published_date"
2018-05-10 17:15:01 +00:00
ordering = ["-published_date", "title", ]
2013-06-06 21:25:36 +00:00
class CommentAdmin(ModelAdmin2):
2013-06-06 21:25:36 +00:00
search_fields = ('body', '=post__title')
list_filter = ['post', ]
actions_on_top = True
actions_on_bottom = True
2013-07-30 14:05:57 +00:00
actions_selection_counter = False
2013-05-19 09:21:25 +00:00
2018-05-10 17:15:01 +00:00
# Register the blog app with a verbose name
djadmin2_site.register_app_verbose_name(
'blog',
gettext_lazy('My Blog')
)
2013-05-19 09:21:25 +00:00
# Register each model with the admin
djadmin2_site.register(Post, PostAdmin)
djadmin2_site.register(Comment, CommentAdmin)