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

from news.models import News


class NewsAdmin(AdminImageMixin, admin.ModelAdmin):
    prepopulated_fields = {'slug': ('title',)}
    list_display = ('title', 'date_created', 'date_updated')
    list_filter = ('author',)
    search_fields = ['title', 'content']
    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)