﻿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
32122	Querying GenericIPAddressField for inexact matches requires use of QuerySet.extra	Peter Law	nobody	"Given some model with a `GenericIPAddressField` field, I'd like to be able to query for IP addresses which are contained within ranges expressed by existing rows in the database (and also be able to do the inverse - query for rows matching a range).
I'm not sure if this is something which databases other than Postgres support natively though.

{{{#!python
class There(models.Model):
    ip_address = models.GenericIPAddressField()

There.objects.create(ip_address='127.0.0.1/16')
There.objects.create(ip_address='1.1.1.1')

# I want this (or something like it) to return the first entry:
There.objects.get(ip_address__contains='127.0.0.2')
# Just like this does
There.objects.extra(where=(""ip_address >> '127.0.0.2'"",)).get()

# Similarly, I want this (or something like it) to return the second entry:
There.objects.get(ip_address__contained_by='1.1.0.0/16')
# Just like this does
There.objects.extra(where=(""ip_address << '1.1.0.0/16'"",)).get()
}}}

Currently the first example here ends up using the naive interpretation of `contains` -- surrounding the IP address with `%` and searching for that. For this reason there may be a need to pick a different keyword.

https://www.postgresql.org/docs/11/functions-net.html contains all the operators which Postgres supports, it would be great if Django supported them too.

Alternatively, if there's another way to achieve this which doesn't rely on `QuerySet.extra` and which I've missed then I'd be happy to use that."	Uncategorized	closed	Database layer (models, ORM)	2.2	Normal	wontfix	QuerySet.extra		Unreviewed	0	0	0	0	0	0
