summaryrefslogtreecommitdiff
path: root/sublab_project/news/admin.py
blob: 1f89f256492fa2f92f28c626379f3c552e3a9cd3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from django.contrib import admin
from sorl.thumbnail.admin import AdminImageMixin
from preview_admin import PreviewAdmin

from news.models import News
from utils import render_creole


class NewsAdmin(AdminImageMixin, PreviewAdmin):
    prepopulated_fields = {'slug': ('title',)}
    list_display = ('title', 'date_created', 'date_updated')
    list_filter = ('author',)
    search_fields = ['title', 'content']
    preview_fields = { 'content': render_creole }
    date_hierarchy = 'date_updated'

    def save_model(self, request, obj, form, change):
        if not obj.id:
            obj.author = request.user
        obj.save()

admin.site.register(News, NewsAdmin)