You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If we have a model MyModel with field datetime, and two instances of this model:
instance1: datetime = 2022-02-24T18:45:12.1653Z
instance2: datetime = 2022-02-24T20:02:33.233Z
If we apply the API filter: ?datetime__range=2022-02-24T19:00:00Z,2022-02-24T22:00:00Z, we expect to get the instance 2 in the results of the request, but we have both results, because what is actually done is a datetime__range=2022-02-24T00:00:00Z,2022-02-24T23:59:59Z
Description of the problem
Concrete range / comparaison filters use a method
convert_type
that takes an argumentclose_period
(defaults toTrue
):For
DateTime
fields, ifclose_period
is true, we consider the end of the day, otherwise we consider the start of the day.Example:
If we have a model
MyModel
with fielddatetime
, and two instances of this model:datetime = 2022-02-24T18:45:12.1653Z
datetime = 2022-02-24T20:02:33.233Z
If we apply the API filter:
?datetime__range=2022-02-24T19:00:00Z,2022-02-24T22:00:00Z
, we expect to get the instance 2 in the results of the request, but we have both results, because what is actually done is adatetime__range=2022-02-24T00:00:00Z,2022-02-24T23:59:59Z
Fix
Supported formats for DateTime filters
YYYY-MM-DD
: (regex:r'^\d{4}-\d{2}-\d{2}$'
)YYYY-MM-DDTHH:mm:ssZ
: (regex:r'^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$'
)YYYY-MM-DDTHH:mm:ss.xxxxxxZ
: (regex:r'^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,6})?Z$'
)Possible filters
Comparaison filters
YYYY-MM-DD
YYYY-MM-DDTHH:mm:ssZ
YYYY-MM-DDTHH:mm:ss.xxxxxxZ
__gte
dt.start_of('day')
dt.start_of('second')
dt
__gt
dt.end_of('day')
dt.end_of('second')
dt
__lte
dt.end_of('day')
dt.end_of('second')
dt
__lt
dt.start_of('day')
dt.start_of('second')
dt
Range filters
For the range filter:
__range=datetime_min,datetime_max
:YYYY-MM-DD
YYYY-MM-DDTHH:mm:ssZ
YYYY-MM-DDTHH:mm:ss.xxxxxxZ
datetime_min
dt.start_of('day')
dt.start_of('second')
dt
datetime_max
dt.end_of('day')
dt.end_of('second')
dt
The text was updated successfully, but these errors were encountered: