Skip to main content

Proper CIDR fields for Django running on any database

Project description

cidrfield provides a model field for django that allows the storage of an ip network on the db side by using ipaddress to handle conversion to an ipaddress.ip_network instance (or None) on the python side. It supports the use of __contains and __in to query the IP network that contain and belong to.


Add this to your django project by installing with pip:

pip install django-cidrfield


In your models, do something like the following:

from django.db import models
from cidrfield.models import IPNetworkField

class MyModel(models.Model):

    # the regular params should work well enough here
    ip_network = IPNetworkField()
    # ... and so on

Then you can store a ip network like the following:


And you can query a ip network like the following:


Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for django-cidrfield, version 0.1.3
Filename, size File type Python version Upload date Hashes
Filename, size django_cidrfield-0.1.3-py3-none-any.whl (5.0 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size django-cidrfield-0.1.3.tar.gz (3.4 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page