equal
deleted
inserted
replaced
|
1 from django import forms |
|
2 |
|
3 from offline.event.models import Event |
|
4 |
|
5 class EventCreateForm(forms.ModelForm): |
|
6 |
|
7 class Meta: |
|
8 model = Event |
|
9 fields = ['title', 'start_date', 'stop_date'] |
|
10 |
|
11 def clean_start_date(self): |
|
12 return self.cleaned_data['start_date'] |
|
13 |
|
14 def clean_stop_date(self): |
|
15 |
|
16 stop_date = self.cleaned_data['stop_date'] |
|
17 start_date = self.clean_start_date() |
|
18 |
|
19 if start_date > stop_date: |
|
20 raise forms.ValidationError("Event cannot stop before it starts") |
|
21 |
|
22 return self.cleaned_data['stop_date'] |