Add game answer functionality with form and view for user responses
This commit is contained in:
parent
6dbb1a54e0
commit
d03d3b48d4
9 changed files with 97 additions and 12 deletions
|
@ -39,3 +39,22 @@ class MusikGameForm(forms.ModelForm):
|
|||
kwargs["initial"].setdefault("players", players)
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields["players"].queryset = players
|
||||
|
||||
|
||||
class AnswerForm(forms.Form):
|
||||
def __init__(self, *args, **kwargs):
|
||||
game = kwargs.pop("game")
|
||||
user = kwargs.pop("user")
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
for music in game.musicgameorder_set.all():
|
||||
self.fields[f"answer-{music.order}"] = forms.ChoiceField(
|
||||
choices=[("", "")]
|
||||
+ list(game.players.all().values_list("id", "username")),
|
||||
required=False,
|
||||
label=music.order,
|
||||
initial=ma.answer.id
|
||||
if (ma := music.musicgameanswer_set.filter(player=user).first())
|
||||
and ma.answer
|
||||
else "",
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue