init
This commit is contained in:
29
schedule/forms.py
Normal file
29
schedule/forms.py
Normal file
@ -0,0 +1,29 @@
|
||||
from django import forms
|
||||
from .models import Lesson, LessonEnrollment
|
||||
|
||||
class LessonForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Lesson
|
||||
fields = ['course', 'date', 'start_time', 'end_time', 'location', 'max_students']
|
||||
widgets = {
|
||||
'date': forms.DateInput(attrs={'type': 'date'}),
|
||||
'start_time': forms.TimeInput(attrs={'type': 'time'}),
|
||||
'end_time': forms.TimeInput(attrs={'type': 'time'}),
|
||||
}
|
||||
|
||||
def clean(self):
|
||||
cleaned_data = super().clean()
|
||||
start_time = cleaned_data.get('start_time')
|
||||
end_time = cleaned_data.get('end_time')
|
||||
|
||||
if start_time and end_time:
|
||||
# Проверяем, что время окончания больше времени начала
|
||||
if start_time.time() >= end_time:
|
||||
raise forms.ValidationError('Время окончания должно быть позже времени начала')
|
||||
|
||||
return cleaned_data
|
||||
|
||||
class EnrollmentForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = LessonEnrollment
|
||||
fields = ['lesson', 'student']
|
Reference in New Issue
Block a user