CUSTOM_LOOKUP_TYPES_ MAP t- Less than days ago lambda key value None s

 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
CUSTOM_LOOKUP_TYPES_MAP = {
">t-": ("Less than days ago", lambda key, value=None: {
'%s__gte' % key: _truncate(now() - timedelta(days=int(value)))
}),
"<t-": ("More than days ago", lambda key, value=None: {
'%s__lte' % key: _truncate(now() - timedelta(days=int(value)))
}),
"><t-": ("In the past", lambda key, value=None: {
'%s__gte' % key: _truncate(now() - timedelta(days=int(value))),
'%s__lt' % key: _truncate(now() + timedelta(days=1))
}),
"t-": ("Days ago", lambda key, value=None: {
'%s__gte' % key: _truncate(now() - timedelta(days=int(value))),
'%s__lte' % key: _truncate(now() - timedelta(days=(int(value)-1))),
}),
"><tp": ("In the next", lambda key, value=None: {
'%s__gte' % key: _truncate(now()),
'%s__lte' % key: _truncate(now() + timedelta(days=int(value)))
}),
"t": ("Today", lambda key, value=None: {
'%s__gte' % key: _truncate(now()),
'%s__lte' % key: _truncate(now() + timedelta(days=1)),
}),
"ld": ("Yesterday", lambda key, value=None: {
'%s__gte' % key: _truncate(now() - timedelta(days=1)),
'%s__lte' % key: _truncate(now()),
}),
"m": ("This month", lambda key, value=None: {
'%s__gte' % key: _truncate(now().replace(day=1)),
'%s__lt' % key: _truncate((now() + relativedelta(months=1)).replace(day=1))
}),
"lm": ("Last month", lambda key, value=None: {
'%s__gte' % key: _truncate((now() + relativedelta(months=-1)).replace(day=1)),
'%s__lt' % key: _truncate(now().replace(day=1))
}),
"y": ("This year", lambda key, value=None: {
'%s__gte' % key: _truncate(now().replace(month=1, day=1)),
'%s__lt' % key: _truncate((now() + relativedelta(years=1)).replace(month=1, day=1))
}),
"dft": ("Days from today", lambda key, value=None: {
'%s__gte' % key: _truncate(now() - relativedelta(days=int(value))),
'%s__lte' % key: _truncate(now() + relativedelta(days=int(value)))
})
}