Skip to content

Commit 2dde3a1

Browse files
committed
feat: #BOOK-2024 date operator before and after
1 parent 46eeaee commit 2dde3a1

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/django_smartbase_admin/actions/advanced_filters.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,19 @@ class AllOperators(models.TextChoices):
4343
IS_NOT_EMPTY = "is_not_empty", _("Equal")
4444
IS_NULL = "is_null", _("Is null")
4545
IS_NOT_NULL = "is_not_null", _("Is not null")
46+
BEFORE = "before", _("Before")
47+
AFTER = "after", _("After")
4648

4749

50+
DATE_ATTRIBUTES = [
51+
AllOperators.BETWEEN,
52+
AllOperators.NOT_BETWEEN,
53+
AllOperators.BEFORE,
54+
AllOperators.AFTER,
55+
AllOperators.IS_NULL,
56+
AllOperators.IS_NOT_NULL,
57+
]
58+
4859
NUMBER_ATTRIBUTES = [
4960
AllOperators.BETWEEN,
5061
AllOperators.NOT_BETWEEN,
@@ -135,6 +146,8 @@ class QueryBuilderService:
135146
AllOperators.IS_NOT_EMPTY.value: "__exact",
136147
AllOperators.IS_NULL.value: "__isnull",
137148
AllOperators.IS_NOT_NULL.value: "__isnull",
149+
AllOperators.BEFORE.value: "__lt",
150+
AllOperators.AFTER.value: "__gte",
138151
}
139152

140153
ZERO_INPUTS_OPERATORS = {
@@ -312,7 +325,9 @@ def get_all_operators_for_query_builder(cls):
312325
number_of_inputs = 0
313326
else:
314327
number_of_inputs = 1
315-
operators.append({"type": key, "nb_inputs": number_of_inputs})
328+
operators.append(
329+
{"type": key, "nb_inputs": number_of_inputs, "apply_to": "string"}
330+
)
316331
return json.dumps(operators), json.dumps(operators_translations)
317332

318333
@classmethod

src/django_smartbase_admin/engine/filter_widgets.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
AllOperators,
1212
STRING_ATTRIBUTES,
1313
NUMBER_ATTRIBUTES,
14+
DATE_ATTRIBUTES,
1415
)
1516
from django_smartbase_admin.engine.admin_view import SBAdminView
1617
from django_smartbase_admin.engine.const import (
@@ -298,7 +299,7 @@ def __init__(
298299
)
299300

300301
def get_advanced_filter_operators(self):
301-
return NUMBER_ATTRIBUTES
302+
return DATE_ATTRIBUTES
302303

303304
def get_shortcuts(self):
304305
now = timezone.now()

0 commit comments

Comments
 (0)