39004-vm/core/forms.py
2026-03-05 11:04:00 +00:00

29 lines
890 B
Python

from django import forms
from .models import Character, Choice
class CharacterCreateForm(forms.Form):
name = forms.CharField(
max_length=80,
widget=forms.TextInput(attrs={"class": "form-control", "placeholder": "Имя ведьмака"}),
)
background = forms.ChoiceField(
choices=Character.BACKGROUND_CHOICES,
widget=forms.Select(attrs={"class": "form-select"}),
)
class ChoiceForm(forms.Form):
choice = forms.ModelChoiceField(
queryset=Choice.objects.none(),
empty_label=None,
widget=forms.RadioSelect,
)
def __init__(self, *args, **kwargs):
choice_queryset = kwargs.pop("choice_queryset", Choice.objects.none())
super().__init__(*args, **kwargs)
self.fields["choice"].queryset = choice_queryset
self.fields["choice"].widget.attrs.update({"class": "choice-radio"})