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

from news.models import News


class NewsAdmin(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)