kers/events/admin.py

45 lines
1,022 B
Python
Raw Normal View History

from django import forms
2020-08-04 03:32:02 +02:00
from django.contrib import admin
from .models import Event, EventRegistration, TimeSlot
2020-07-21 22:24:45 +02:00
2020-08-04 03:32:02 +02:00
class TimeSlotFormSet(forms.BaseInlineFormSet):
def __init__(self, *args, **kwargs):
kwargs["initial"] = [
{"time": TimeSlot.EVENING}
]
super().__init__(*args, **kwargs)
2020-07-22 04:08:30 +02:00
2020-07-22 05:02:01 +02:00
class RegistrationFormSet(forms.BaseInlineFormSet):
def __init__(self, *args, **kwargs):
kwargs["initial"] = [
{"state": EventRegistration.ADMITTED}
]
super().__init__(*args, **kwargs)
2020-08-04 03:32:02 +02:00
class TimeSlotInline(admin.StackedInline):
model = TimeSlot
extra = 1
formset = TimeSlotFormSet
class RegistrationInline(admin.TabularInline):
2020-07-22 05:02:01 +02:00
model = EventRegistration
extra = 1
formset = RegistrationFormSet
2020-08-04 03:32:02 +02:00
#
2020-07-22 05:02:01 +02:00
class EventAdmin(admin.ModelAdmin):
2020-08-04 03:32:02 +02:00
inlines = [TimeSlotInline]
class TimeSlotAdmin(admin.ModelAdmin):
2020-07-22 05:02:01 +02:00
inlines = [RegistrationInline]
2020-08-04 03:32:02 +02:00
2020-07-22 05:02:01 +02:00
admin.site.register(Event, EventAdmin)
2020-08-04 03:32:02 +02:00
admin.site.register(TimeSlot, TimeSlotAdmin)