from charts.models import ChartRecord
from django.contrib import admin


@admin.register(ChartRecord)
class ChartRecordAdmin(admin.ModelAdmin):
    date_hierarchy = "created"
    list_display = (
        "user",
        "rank",
        "count",
        "year",
        "month",
        "week",
        "day",
        "media_name",
        "media_type",
    )
    list_filter = (
        "user",
        "year",
        "month",
        "week",
        "day",
    )
    ordering = ("-created",)
    search_fields = (
        "artist__name",
        "album__name",
        "track__title",
        "tv_series__name",
        "video__title",
        "podcast__name",
        "board_game__name",
        "book__title",
        "food__name",
        "trail__name",
    )
    raw_id_fields = (
        "user",
        "artist",
        "album",
        "track",
        "tv_series",
        "video",
        "podcast",
        "podcast_episode",
        "board_game",
        "trail",
        "geo_location",
        "food",
        "book",
    )

    def media_name(self, obj):
        return obj.media_obj

    def media_type(self, obj):
        return obj.media_type
