-
Notifications
You must be signed in to change notification settings - Fork 29
Description
Description
Let's make it easier to filter time fields through query sets by adding support for a set of new predicates that will allow to filter based on specific time attributes.
New predicates
year
The new year predicate should allow filtering date_time and date fields based on a specific year:
Book.filter(created_at__year: 2024)month
The new month predicate should allow filtering date_time and date fields based on a specific month (with 1 being and January and 12 being December):
Book.filter(created_at__month: 12)day
The new day predicate should allow filtering date_time and date fields based on a specific day number (regardless of the actual month):
Book.filter(created_at__day: 28)hour
The new hour predicate should allow filtering date_time fields based on a specific hour value (integer between 0 and 23):
Book.filter(created_at__hour: 23)minute
The new minute predicate should allow filtering date_time fields based on a specific minute value (integer between 0 and 59):
Book.filter(created_at__minute: 55)second
The new second predicate should allow filtering date_time fields based on a specific second value (integer between 0 and 59):
Book.filter(created_at__second: 45)Chaining of predicates
The introduction of these new predicates could also be accompanied by the support for chaining query set predicates. This is especially relevant for time attribute filtering where it's common to target records for which a specific time property is greater than or less than a give number.
As such, we should also explore enabling the use of chained query set predicates for the new time predicates that will be introduced here. For example:
Book.filter(created_at__year__gte: 2022)