Skip to main content

django-cidrfield

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='192.168.1.0/24')
MyModel.objects.filter(ip_network__contains='192.168.1.1')
MyModel.objects.filter(ip_network__in='192.168.0.0/16')
MyModel.objects.filter(ip_network__in=['192.168.0.0/16', '10.10.0.0/16'])

If you use DjangoQL, you can use CIDRQLSchema like the following:

from django.contrib import admin
from djangoql.admin import DjangoQLSearchMixin
from cidrfield.schemas import CIDRQLSchema
from .models import MyModel


@admin.register(MyModel)
class MyModelAdmin(DjangoQLSearchMixin, admin.ModelAdmin):
    list_display = ['ip_network']
    search_fields = ('ip_network', )
    djangoql_schema = CIDRQLSchema

Changelog

0.2.0

  • Add support for Djangoql.

  • Fixed the bug about __in query not supporting array.

Metadata

Release files for django-cidrfield 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-cidrfield 0.2.0
File Size Uploaded Provenance Actions
django-cidrfield-0.2.0.tar.gz 4.1 kB Without provenance Details for django-cidrfield-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-cidrfield 0.2.0
File Interpreter ABI Platform Actions
django_cidrfield-0.2.0-py3-none-any.whl Python 3 none any Details for django_cidrfield-0.2.0-py3-none-any.whl

Total release size: 10.1 kB

Release files / django-cidrfield-0.2.0.tar.gz

Download URL django-cidrfield-0.2.0.tar.gz
Size 4.1 kB
Tags Source
SHA-256 checksum
How to use checksums
d367abca917c26f6e3f7008bfe50dc7d664644c7457dad1253b9497cb760fb83
BLAKE2b-256 checksum
How to use checksums
414b3fe740fd379c830ef23e1489ba43c3b89d26cfddc08551c9124567222d92
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / django_cidrfield-0.2.0-py3-none-any.whl

Download URL django_cidrfield-0.2.0-py3-none-any.whl
Size 5.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
94e7968fb0977eb206f5eca03ffcd09b579ffca2b89aa574d590e247444f9971
BLAKE2b-256 checksum
How to use checksums
dfb8e909ea3808b7e5dd3a28a5497cb18d31f46bfaedacdd2e1c4db002b3b20a
Upload date
Uploaded using Trusted Publishing?
What is 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

Security for django-cidrfield 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page