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
Release history Release notifications | RSS feed
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 hashes)
Built Distribution
Close
Hashes for django_cidrfield-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca372774c6d6ab02dd6e0880052c107b0e71e723ba5f98bce6401ec199d3af13 |
|
MD5 | 71f4fd7858f620fa6fb3aa000e6d91bf |
|
BLAKE2b-256 | 6d83a69afc91b424fbccb64a779c128cefd34a5c6eaea9f6e19c694e38f3fb7d |