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)