-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathforms.py
67 lines (54 loc) · 1.84 KB
/
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from typing import Iterable
from django import forms
from django_filters import DateFilter, FilterSet
from dev.myapp.models import Event
from django_flatpickr.widgets import (
DatePickerInput,
DateTimePickerInput,
TimePickerInput,
)
class MyDatePickerInput(DatePickerInput):
template_name = "myapp/custom-flatpickr-input.html"
class EventFilter(FilterSet): # type: ignore
start_date__gt = DateFilter(
field_name="start_date",
lookup_expr="gt",
widget=MyDatePickerInput(),
)
start_date__lt = DateFilter(
field_name="start_date",
lookup_expr="lt",
widget=MyDatePickerInput(range_from="start_date__gt"),
)
class Meta:
model = Event
fields: Iterable[str] = []
class ToDoForm(forms.Form):
start_date = forms.DateField(label="Start Date", widget=DatePickerInput())
end_date = forms.DateField(
label="End Date", widget=DatePickerInput(range_from="start_date")
)
class CustomInputTemplateToDoForm(forms.Form):
start_date = forms.DateField(label="Start Date", widget=MyDatePickerInput())
end_date = forms.DateField(
label="End Date", widget=MyDatePickerInput(range_from="start_date")
)
class EventForm(forms.ModelForm[Event]):
class Meta:
model = Event
fields = [
"start_date",
"end_date",
"start_time",
"end_time",
"start_datetime",
"end_datetime",
]
widgets = {
"start_date": DatePickerInput(),
"end_date": DatePickerInput(range_from="start_date"),
"start_time": TimePickerInput(),
"end_time": TimePickerInput(range_from="start_time"),
"start_datetime": DateTimePickerInput(),
"end_datetime": DateTimePickerInput(range_from="start_datetime"),
}