from django.contrib import admin

from import_export.admin import ExportMixin
from sorl.thumbnail.admin import AdminImageMixin

from models import Announcement


class AnnouncementAdmin(AdminImageMixin, ExportMixin, admin.ModelAdmin):
    save_on_top = True
    readonly_fields = ['created', 'updated', 'is_published']
    search_fields = ['title']
    list_display = ['title', 'publish_from', 'publish_until', 'is_published']
    list_editable = ['publish_from', 'publish_until']

    def is_published(self, obj):
        return obj.published
    is_published.boolean = True

admin.site.register(Announcement, AnnouncementAdmin)
