from django.contrib import admin
from comments.models import Comment


@admin.register(Comment)
class CommentAdmin(admin.ModelAdmin):
    list_display = ['id', 'content_preview', 'post', 'created_by', 'created_at', 'is_active']
    search_fields = ['content', 'created_by__username', 'post__content']
    list_filter = ['created_at', 'is_active']
    ordering = ['-created_at']
    readonly_fields = ['created_at', 'updated_at']

    def content_preview(self, obj):
        return obj.content[:50] + '...' if len(obj.content) > 50 else obj.content
    content_preview.short_description = 'Contenu'