from django.contrib import admin
from .models import *

class CalendarAdmin(admin.ModelAdmin):
#    prepopulated_fields = {"slug": ("shortname",)}
    list_display = ("name", "shortcode", "published")


class ScraperAdmin(admin.ModelAdmin):
#    prepopulated_fields = {"slug": ("shortname",)}
    list_display = ("name", "items", "new_items", "last_ran", "calendar")

class OrganizationAdmin(admin.ModelAdmin):
#    prepopulated_fields = {"slug": ("shortname",)}
    list_display = ( "name", "city",)
    list_filter = ("city",)

class EventAdmin(admin.ModelAdmin):
#    prepopulated_fields = {"slug": ("shortname",)}
    list_display = ( "show_title", "event_type", "show_date", "scraper")
    list_filter = ("calendar", "event_type", "scraper",)

class PromoAdmin(admin.ModelAdmin):
#    prepopulated_fields = {"slug": ("shortname",)}
    list_display = ("title", "organization", "get_calendars", "published", "promo_image")
    list_filter = ("calendar__shortcode", "promo_type")

    def get_calendars(self, obj):
        return "\n".join([p.shortcode for p in obj.calendar.all()])


# Register your models here.
admin.site.register(Promo, PromoAdmin)
admin.site.register(Event, EventAdmin)
admin.site.register(Scraper, ScraperAdmin)
admin.site.register(Calendar, CalendarAdmin)
admin.site.register(Organization, OrganizationAdmin)
