From 9a649317dac7178e637d247e4a9cc403b56a8c9b Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Sun, 15 Nov 2020 20:13:09 +0100 Subject: [PATCH] Add forms --- lg/forms.py | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 lg/forms.py diff --git a/lg/forms.py b/lg/forms.py new file mode 100644 index 0000000..cd09c07 --- /dev/null +++ b/lg/forms.py @@ -0,0 +1,55 @@ +from django import forms + +from .models import Action, CupidonAction, DoveAction, HackerAction, RavenAction, WerewolfAction, WitchAction + + +class ActionForm(forms.ModelForm): + _forms_per_model = dict() + + def __init_subclass__(cls): + ActionForm._forms_per_model[cls.Meta.model] = cls + return super().__init_subclass__() + + @staticmethod + def get_form_class(model_class): + return ActionForm._forms_per_model.get(model_class, ActionForm) + + class Meta: + model = Action + exclude = ('player', 'night',) + + +class WerewolfActionForm(ActionForm): + class Meta: + model = WerewolfAction + exclude = ('player', 'night',) + + +class CupidonActionForm(ActionForm): + class Meta: + model = CupidonAction + exclude = ('player', 'night',) + + +class WitchActionForm(ActionForm): + class Meta: + model = WitchAction + exclude = ('player', 'night',) + + +class RavenActionForm(ActionForm): + class Meta: + model = RavenAction + exclude = ('player', 'night',) + + +class DoveActionForm(ActionForm): + class Meta: + model = DoveAction + exclude = ('player', 'night',) + + +class HackerActionForm(ActionForm): + class Meta: + model = HackerAction + exclude = ('player', 'night',)