﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
31039	Support __contained_by lookup for AutoFields and BigAutoFields.	Bolay Michael	Hasan Ramezani	"`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
}}}

"	New feature	closed	contrib.postgres	dev	Normal	fixed			Accepted	0	0	0	0	1	0
