Первый коммит
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
from django import forms
|
||||
from django.utils import timezone
|
||||
|
||||
from .models import ConsultationRequest
|
||||
|
||||
|
||||
class ConsultationRequestForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = ConsultationRequest
|
||||
fields = (
|
||||
"name",
|
||||
"phone",
|
||||
"contact",
|
||||
"subject",
|
||||
"exam",
|
||||
"preferred_date",
|
||||
"preferred_time",
|
||||
"comment",
|
||||
)
|
||||
widgets = {
|
||||
"name": forms.TextInput(attrs={"placeholder": "Как к вам обращаться"}),
|
||||
"phone": forms.TelInput(attrs={"placeholder": "+7 (999) 123-45-67"}),
|
||||
"contact": forms.TextInput(attrs={"placeholder": "@username, WhatsApp и т. п."}),
|
||||
"preferred_date": forms.DateInput(attrs={"type": "date"}),
|
||||
"preferred_time": forms.TimeInput(attrs={"type": "time"}),
|
||||
"comment": forms.Textarea(
|
||||
attrs={
|
||||
"placeholder": "Например: текущий класс, темы, которые вызывают сложности",
|
||||
"rows": 4,
|
||||
}
|
||||
),
|
||||
}
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
for field in self.fields.values():
|
||||
field.widget.attrs["class"] = "form-control"
|
||||
self.fields["preferred_date"].widget.attrs["min"] = timezone.localdate().isoformat()
|
||||
self.fields["contact"].required = False
|
||||
self.fields["comment"].required = False
|
||||
|
||||
def clean_preferred_date(self):
|
||||
preferred_date = self.cleaned_data["preferred_date"]
|
||||
if preferred_date < timezone.localdate():
|
||||
raise forms.ValidationError("Выберите сегодняшнюю дату или более позднюю.")
|
||||
return preferred_date
|
||||
|
||||
Reference in New Issue
Block a user