from events.models import ChronokiwiEvent, ChronokiwiChronology
from django.contrib.gis import admin
from events.index import event_indexer

class ChronokiwiBaseObjectAdmin(admin.GeoModelAdmin):
    prepopulated_fields = {"slug": ("name",)}
    def save_model(self, request, obj, form, change):
        obj.user = request.user

        obj.save()
        ChronokiwiEvent.indexer.update()

class ChronokiwiEventAdmin(ChronokiwiBaseObjectAdmin):
    pass

        
class ChronokiwiChronologyAdmin(ChronokiwiBaseObjectAdmin):
    pass

admin.site.register(ChronokiwiEvent, ChronokiwiEventAdmin)
admin.site.register(ChronokiwiChronology, ChronokiwiChronologyAdmin)