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.

Installation

Add this to your django project by installing with pip:

pip install django-cidrfield

Usage

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:

MyModel(ip_network='192.168.1.0/24').save()

And you can query a ip network like the following:

MyModel.objects.filter(ip_network__contains='192.168.1.1')
MyModel.objects.filter(ip_network__in='192.168.0.0/16')

Project details


Download files

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

Source Distribution

django-cidrfield-0.1.3.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

django_cidrfield-0.1.3-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file django-cidrfield-0.1.3.tar.gz.

File metadata

  • Download URL: django-cidrfield-0.1.3.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.6.0

File hashes

Hashes for django-cidrfield-0.1.3.tar.gz
Algorithm Hash digest
SHA256 7484e0f86419a97b935b302865852d6fa403eac600b7786482c6e858be2f4afa
MD5 4fe310f15a5e13f69a5f7a7afd54c738
BLAKE2b-256 b78aadcf25bf7ae35ec9c00b26a95feeb03e765bae9ef43b2627cae956a43991

See more details on using hashes here.

File details

Details for the file django_cidrfield-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: django_cidrfield-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.6.0

File hashes

Hashes for django_cidrfield-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 928b79ab8311103398a0272455edacc7fabe90ed13359713ab0f0d012fc8ccf8
MD5 b67faef3dd79252f622419b271437d90
BLAKE2b-256 656485f914bb2ceb7d9d268800152faf860fe393ebd0efd2181f025ef046b015

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page