From 033226a96fb2d57636f079bc792a6384b4647ab9 Mon Sep 17 00:00:00 2001 From: Midgard Date: Wed, 22 Jul 2020 17:02:23 +0200 Subject: [PATCH] Default to 1 registration in admin, "admitted" --- events/admin.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/events/admin.py b/events/admin.py index 3509e89..6d41955 100644 --- a/events/admin.py +++ b/events/admin.py @@ -1,10 +1,21 @@ from django.contrib import admin +from django import forms from .models import Event, EventRegistration -class RegistrationInline(admin.StackedInline): +class RegistrationFormSet(forms.BaseInlineFormSet): + def __init__(self, *args, **kwargs): + kwargs["initial"] = [ + {"state": EventRegistration.ADMITTED} + ] + super().__init__(*args, **kwargs) + + +class RegistrationInline(admin.TabularInline): model = EventRegistration + extra = 1 + formset = RegistrationFormSet class EventAdmin(admin.ModelAdmin): inlines = [RegistrationInline]