Skip to content

Instantly share code, notes, and snippets.

@jaytaylor
Created May 21, 2014 21:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaytaylor/a7f74459a891fbc234d4 to your computer and use it in GitHub Desktop.
Save jaytaylor/a7f74459a891fbc234d4 to your computer and use it in GitHub Desktop.
Django + Postgres CIDR filtering
ip_column_name = 'ip'
keyword = '63.0.0.0/24'
where = '{}::inet << %s::inet::cidr'.format(ip_column_name)
match = MyDjangoModel.objects.all()
match = match.extra(where=[where], params=[keyword])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment