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()

Then you can store 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.2.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: django-cidrfield-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 11904b660df4e3d19b9400a10f6de2e61e60fcea60d3ee1b8f6a9938dbd5f63e
MD5 e9faa24731b46f49ae9ccc969c3522d7
BLAKE2b-256 8b24420e192cd3f652f3fbd48378c6efcd65579e28ff8d3cf37c13764d9b67c1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: django_cidrfield-0.1.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ca372774c6d6ab02dd6e0880052c107b0e71e723ba5f98bce6401ec199d3af13
MD5 71f4fd7858f620fa6fb3aa000e6d91bf
BLAKE2b-256 6d83a69afc91b424fbccb64a779c128cefd34a5c6eaea9f6e19c694e38f3fb7d

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