[Answer]-Use Django ORM to select rows if a value is in a range stored in columns

1đź‘Ť

âś…

I’d suggest reverting the logic of the “WHERE” clause. Provided that you have a suitable IP field, a query may look like this:

GeoIP.objects.filter(start_ip__lte='68.180.194.242', end_ip__gte='68.180.194.242')

For other similar cases, when this “reverting” is not possible, Django provides F objects (see here for examples of usage in queries)

👤Davide

Leave a comment