26 lines
794 B
Python
26 lines
794 B
Python
from django import forms
|
|
from guild.models import PlaySession, Character
|
|
|
|
|
|
class PlaySessionCharacterForm(forms.ModelMultipleChoiceField):
|
|
def label_from_instance(self, character):
|
|
if character.player:
|
|
return "{} ({})".format(character.name, character.player.name)
|
|
else:
|
|
return character.name
|
|
|
|
|
|
class PlaySessionForm(forms.ModelForm):
|
|
characters = PlaySessionCharacterForm(
|
|
queryset=Character.objects.all(), widget=forms.CheckboxSelectMultiple
|
|
)
|
|
|
|
class Meta:
|
|
model = PlaySession
|
|
fields = ["date", "characters", "summary"]
|
|
# set date wideget to type="date"
|
|
widgets = {
|
|
"date": forms.DateInput(attrs={"type": "date"}),
|
|
"summary": forms.Textarea(attrs={"rows": 32}),
|
|
}
|