2013-07-07 14:46:59 +00:00
|
|
|
|
2020-09-26 21:21:43 +00:00
|
|
|
from django.utils.translation import gettext_lazy
|
2013-05-31 15:38:34 +00:00
|
|
|
|
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
|
2016-05-07 23:29:17 +00:00
|
|
|
from djadmin2.site import djadmin2_site
|
|
|
|
|
from djadmin2.types import Admin2TabularInline, ModelAdmin2
|
2013-09-27 03:42:42 +00:00
|
|
|
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
|
|
|
|
2013-05-19 13:32:51 +00:00
|
|
|
|
2016-05-07 23:29:17 +00:00
|
|
|
class CommentInline(Admin2TabularInline):
|
2013-05-19 09:21:25 +00:00
|
|
|
model = Comment
|
|
|
|
|
|
|
|
|
|
|
2016-05-07 23:29:17 +00:00
|
|
|
class PostAdmin(ModelAdmin2):
|
2013-08-02 17:58:57 +00:00
|
|
|
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')
|
2013-07-30 20:28:24 +00:00
|
|
|
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
|
2013-07-30 20:28:24 +00:00
|
|
|
date_hierarchy = "published_date"
|
2018-05-10 17:15:01 +00:00
|
|
|
ordering = ["-published_date", "title", ]
|
2013-06-06 21:25:36 +00:00
|
|
|
|
2013-06-14 13:58:27 +00:00
|
|
|
|
2016-05-07 23:29:17 +00:00
|
|
|
class CommentAdmin(ModelAdmin2):
|
2013-06-06 21:25:36 +00:00
|
|
|
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-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
|
|
|
|
2013-08-05 07:37:51 +00:00
|
|
|
# Register the blog app with a verbose name
|
2016-05-07 23:29:17 +00:00
|
|
|
djadmin2_site.register_app_verbose_name(
|
2013-08-05 07:37:51 +00:00
|
|
|
'blog',
|
2020-09-26 21:21:43 +00:00
|
|
|
gettext_lazy('My Blog')
|
2013-08-05 07:37:51 +00:00
|
|
|
)
|
2013-05-19 09:21:25 +00:00
|
|
|
|
2013-05-18 13:43:44 +00:00
|
|
|
# Register each model with the admin
|
2016-05-07 23:29:17 +00:00
|
|
|
djadmin2_site.register(Post, PostAdmin)
|
|
|
|
|
djadmin2_site.register(Comment, CommentAdmin)
|