aboutsummaryrefslogtreecommitdiff
path: root/weblog/admin.py
blob: aa5acfb5e5357a2d0d3a9024302f5e919a197cb2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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)