lglog/lg/forms.py

56 lines
1.2 KiB
Python
Raw Normal View History

2020-11-15 19:13:09 +00:00
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',)