from django.contrib import admin
from django.contrib.admin.decorators import register
from .models import Expert, WorkExperience, Paper, Project, Award
from simple_history.admin import SimpleHistoryAdmin
# Register your models here.
class WorkExperienceInline(admin.StackedInline):
    model = WorkExperience
    extra = 0
    fields = ('expert', 'name','start_date', 'post')

class PaperInline(admin.StackedInline):
    model = Paper
    extra = 0
    fields = ('expert', 'name','is_leader', 'publish_date')

class ProjectInline(admin.StackedInline):
    model = Project
    extra = 0
    fields = ('expert', 'name','start_date', 'content')

class AwardInline(admin.StackedInline):
    model = Award
    extra = 0
    fields = ('expert', 'name','level', 'issue_date')

@admin.register(Expert)
class ExpertAdmin(SimpleHistoryAdmin):
    date_hierarchy = 'create_time'
    list_display = ('name', 'gender','idnumber', 'create_time')
    search_fields = ("name", "workexperience_expert__name", "paper_expert__name", "project_expert__name", "award_expert__name")
    inlines = [
        WorkExperienceInline,
        ProjectInline,
        PaperInline,
        AwardInline
    ]

@admin.register(WorkExperience)
class WorkExperienceAdmin(admin.ModelAdmin):
    date_hierarchy = 'start_date'
    list_display = ('expert', 'name','start_date', 'post')

@admin.register(Paper)
class PaperAdmin(admin.ModelAdmin):
    date_hierarchy = 'publish_date'
    list_display = ('expert', 'name','is_leader', 'publish_date')
    list_filter = ('is_leader',)

@admin.register(Project)
class ProjectAdmin(admin.ModelAdmin):
    date_hierarchy = 'start_date'
    list_display = ('expert', 'name','number', 'content', 'start_date')
    

@admin.register(Award)
class AwardAdmin(admin.ModelAdmin):
    date_hierarchy = 'issue_date'
    list_display = ('expert', 'name','level', 'issue_date')
    list_filter = ('level',)