#31039: Allow `AutoField` to use `__contained_by` on postgress Range fields
-----------------------------------------+------------------------
Reporter: Bolayniuss | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 2.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
`AutoField` can't use the `__contained_by` relation on postgres Range
fields.
To support it, `RangeContainedBy` lookup class needs to add a map for
`serial` data type and `AutoField` must register this lookup.
Example of unsupported feature
{{{
from django.contrib.postgres.fields import IntegerRangeField
from psycopg2.extras import NumericRange
class Model(models.Model):
pass
class ModelBundle(models.Model):
id_range = IntegerRangeField()
# this query is invalid
Model.objects.filter(id__contained_by=NumericRange(0, 10))
# and thus this one neither is
bundle = ModelBundle.object.get(...)
Model.objects.filter(id__contained_by=bundle.id_range)
}}}
Here is how I fix the missing feature
{{{
from django.contrib.postgres.fields.ranges import RangeContainedBy
class ExtendedRangeContainedBy(RangeContainedBy):
type_mapping = {
'serial': 'int4range', # <---- add serial type mapping
'integer': 'int4range',
'bigint': 'int8range',
'double precision': 'numrange',
'date': 'daterange',
'timestamp with time zone': 'tstzrange',
}
AutoField.register_lookup(ExtendedRangeContainedBy) # <---- register the
lookup for AutoField
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/31039>
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 view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/053.0973f46fa1f57119f664f3982a048190%40djangoproject.com.