from django.contrib import admin
from historical.models import *


class GroupAdmin(admin.ModelAdmin):
    list_display = ("title",)
    search_fields = (
        "title",
        "description",
    )
    prepopulated_fields = {"slug": ("title",)}

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


class HistoricArticleAdmin(admin.ModelAdmin):
    raw_id_fields = ("story",)
    list_display = (
        "story",
        "group",
        "published_on",
    )

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


admin.site.register(Group, GroupAdmin)
admin.site.register(HistoricArticle, HistoricArticleAdmin)
