from django import forms from django.contrib import admin from .models import Event, EventRegistration, TimeSlot class TimeSlotFormSet(forms.BaseInlineFormSet): def __init__(self, *args, **kwargs): kwargs["initial"] = [ {"time": TimeSlot.EVENING} ] super().__init__(*args, **kwargs) class RegistrationFormSet(forms.BaseInlineFormSet): def __init__(self, *args, **kwargs): kwargs["initial"] = [ {"state": EventRegistration.ADMITTED} ] super().__init__(*args, **kwargs) class TimeSlotInline(admin.StackedInline): model = TimeSlot extra = 1 formset = TimeSlotFormSet class RegistrationInline(admin.TabularInline): model = EventRegistration extra = 1 formset = RegistrationFormSet # class EventAdmin(admin.ModelAdmin): inlines = [TimeSlotInline] class TimeSlotAdmin(admin.ModelAdmin): inlines = [RegistrationInline] admin.site.register(Event, EventAdmin) admin.site.register(TimeSlot, TimeSlotAdmin)