#28851: Support Open Ranges for Range Lookup - convert None to 'infinity'
-------------------------------------+-------------------------------------
Reporter: Sven R. | Owner: nobody
Kunze |
Type: New | Status: new
feature |
Component: Database | Version: 1.11
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Hi Dev Team,
we recently came across the following issue. We wanted to search for an
open ranges using the range lookup.
{{{
Model.objects.filter(date__range=(None, now()))
Model.objects.filter(date__range=(now(), None))
}}}
Right now, we monkey-patch Django like this:
{{{
from django.db.models.lookups import Range
class OpenRange(Range):
lookup_name = 'range'
def as_sql(self, compiler, connection):
lhs, lhs_params = self.process_lhs(compiler, connection)
rhs, rhs_params = self.process_rhs(compiler, connection)
if not rhs_params[0]:
rhs_params[0] = '-infinity'
if not rhs_params[1]:
rhs_params[1] = 'infinity'
return "%s BETWEEN %s AND %s" % (lhs, rhs[0], rhs[1]), rhs_params
models.DateField.register_lookup(OpenRange)
}}}
Cheers,
Sven
--
Ticket URL: <https://code.djangoproject.com/ticket/28851>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/050.46dbda82a449d8d2d721c5be1a5cf2a8%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.