Add forms

This commit is contained in:
Yohann D'ANELLO 2020-11-15 20:13:09 +01:00
parent c04794081b
commit 9a649317da

55
lg/forms.py Normal file
View File

@ -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',)