2023-06-10 20:32:45 +00:00
|
|
|
from django import forms
|
2023-06-20 19:22:56 +00:00
|
|
|
from guild.models import PlaySession, Character, Reward
|
|
|
|
from django.utils.translation import gettext as _
|
2023-06-19 18:01:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
class PlaySessionCharacterForm(forms.ModelMultipleChoiceField):
|
|
|
|
def label_from_instance(self, character):
|
|
|
|
if character.player:
|
|
|
|
return "{} ({})".format(character.name, character.player.name)
|
|
|
|
else:
|
|
|
|
return character.name
|
2023-06-10 20:32:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
class PlaySessionForm(forms.ModelForm):
|
2023-06-19 18:01:33 +00:00
|
|
|
characters = PlaySessionCharacterForm(
|
|
|
|
queryset=Character.objects.all(), widget=forms.CheckboxSelectMultiple
|
|
|
|
)
|
|
|
|
|
2023-06-10 20:32:45 +00:00
|
|
|
class Meta:
|
|
|
|
model = PlaySession
|
|
|
|
fields = ["date", "characters", "summary"]
|
|
|
|
# set date wideget to type="date"
|
|
|
|
widgets = {
|
|
|
|
"date": forms.DateInput(attrs={"type": "date"}),
|
2023-06-13 20:09:25 +00:00
|
|
|
"summary": forms.Textarea(attrs={"rows": 32}),
|
2023-06-10 20:32:45 +00:00
|
|
|
}
|
2023-06-20 19:22:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
class RewardForm(forms.ModelForm):
|
|
|
|
character = forms.ModelChoiceField(
|
|
|
|
queryset=Character.objects.all(),
|
|
|
|
empty_label="All Guild Members",
|
|
|
|
required=False,
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Reward
|
|
|
|
fields = ["amount", "resource", "character"]
|