from django.contrib import admin
from mptt.admin import MPTTModelAdmin
from .models import Post, PostCategory


@admin.register(PostCategory)
class PostCategoryAdmin(MPTTModelAdmin):
    list_display = ("name", "slug", "created_at")
    search_fields = ("name", "slug")
    prepopulated_fields = {"slug": ("name",)}


@admin.register(Post)
class PostAdmin(admin.ModelAdmin):
    list_display = ("title", "category", "status", "published_at", "created_at")
    list_filter = ("status", "category")
    search_fields = ("title", "slug", "content")
    prepopulated_fields = {"slug": ("title",)}
    autocomplete_fields = ("category", "author")
