Opened 5 years ago
Closed 5 years ago
#31039 closed New feature (fixed)
Support __contained_by lookup for AutoFields and BigAutoFields.
Reported by: | Bolay Michael | Owned by: | Hasan Ramezani |
---|---|---|---|
Component: | contrib.postgres | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
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
Change History (5)
comment:1 by , 5 years ago
Component: | Uncategorized → contrib.postgres |
---|---|
Summary: | Allow `AutoField` to use `__contained_by` on postgress Range fields → Support __contained_by lookup for AutoFields and BigAutoFields. |
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → New feature |
Version: | 2.2 → master |
comment:2 by , 5 years ago
Easy pickings: | set |
---|
comment:3 by , 5 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
Note:
See TracTickets
for help on using tickets.
Agreed, we should support
__contained_by
lookup forAutoField
's andBigAutoField
's.