diff options
author | Yaroslsav-95 <contact@yaroslavps.com> | 2018-01-31 08:27:11 +0300 |
---|---|---|
committer | Yaroslsav-95 <contact@yaroslavps.com> | 2018-01-31 08:27:11 +0300 |
commit | 28b67ad39af15d27bad7e55a0ae7fafe91139239 (patch) | |
tree | b94b7d55bfc8b95f2a3c0b96fe17d6eeee85589f /weblog/admin.py | |
parent | 40949b252c9929c755715d3e32df47cd82b095a0 (diff) | |
download | w3blog-28b67ad39af15d27bad7e55a0ae7fafe91139239.tar.gz w3blog-28b67ad39af15d27bad7e55a0ae7fafe91139239.zip |
Initial
Diffstat (limited to 'weblog/admin.py')
-rw-r--r-- | weblog/admin.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/weblog/admin.py b/weblog/admin.py new file mode 100644 index 0000000..1b4e128 --- /dev/null +++ b/weblog/admin.py @@ -0,0 +1,46 @@ +from django.contrib import admin +from django_summernote.admin import SummernoteModelAdmin, SummernoteInlineModelAdmin +from .apps import SETTINGS as blog_settings +from .models import BlogPost, Translation, PostComment, Category, CategoryTranslation + + +blogPostInlines = [] +categoryInlines = [] + +class TranslationInline(admin.StackedInline, SummernoteInlineModelAdmin): + model = Translation + extra = 1 + +class CategoryTranslationInline(admin.StackedInline): + model = CategoryTranslation + extra = 1 + +class PostCommentInline(admin.StackedInline): + model = PostComment + extra = 0 + +if blog_settings['multilingual']: + blogPostInlines.append(TranslationInline) + categoryInlines.append(CategoryTranslationInline) + +if blog_settings['enable_comments']: + blogPostInlines.append(PostCommentInline) + +class BlogPostAdmin(SummernoteModelAdmin): + list_display = ['title', 'author', 'publish_date'] + list_filter = ['publish_date', 'categories'] + inlines = blogPostInlines + summer_note_fields = '__all__' + + def get_form(self, request, obj=None, **kwargs): + if not blog_settings['multilingual']: + self.exclude = ('original_language', ) + form = super(BlogPostAdmin, self).get_form(request, obj, **kwargs) + return form + +class CategoryAdmin(admin.ModelAdmin): + list_display = ['name'] + inlines = categoryInlines + +admin.site.register(BlogPost, BlogPostAdmin) +admin.site.register(Category, CategoryAdmin) |