-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathforms.py
30 lines (23 loc) · 1010 Bytes
/
forms.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from django import forms
from django.db.models import Count
from django.utils.translation import gettext_lazy as _
from scheduler.models import Shift, ShiftMessageToHelpers
class RegisterForShiftForm(forms.Form):
leave_shift = forms.ModelChoiceField(queryset=Shift.objects, required=False)
join_shift = forms.ModelChoiceField(
queryset=Shift.objects.annotate(volunteer_count=Count("helpers")),
required=False,
)
class ShiftMessageToHelpersModelForm(forms.ModelForm):
message = forms.TextInput(attrs={"class": "form-control"})
def __init__(self, *args, **kwargs):
super(ShiftMessageToHelpersModelForm, self).__init__(*args, **kwargs)
for visible in self.visible_fields():
visible.field.widget.attrs["class"] = "form-control"
class Meta:
model = ShiftMessageToHelpers
fields = ["message", "shift"]
widgets = {
"shift": forms.HiddenInput(),
}
labels = {"message": _("Write a message")}