from django.contrib import admin
from .models import ExtractionTask, ExtractedUser

class ExtractedUserInline(admin.TabularInline):
    model = ExtractedUser
    extra = 0

@admin.register(ExtractionTask)
class ExtractionTaskAdmin(admin.ModelAdmin):
    list_display = ('id', 'task_type', 'created_at', 'user_count')
    list_filter = ('task_type', 'created_at')
    inlines = [ExtractedUserInline]
    
    def user_count(self, obj):
        return obj.users.count()
    user_count.short_description = '用户数量'

@admin.register(ExtractedUser)
class ExtractedUserAdmin(admin.ModelAdmin):
    list_display = ('nickname', 'xhs_id', 'task', 'extracted_at')
    search_fields = ('nickname', 'xhs_id', 'comment_text')