Skip to main content

Django PostgreSQL netfields implementation

Project description

https://secure.travis-ci.org/adamcik/django-postgresql-netfields.png

This project is an attempt at making proper PostgreSQL net related fields for Django. In Django pre 1.4 the built in IPAddressField does not support IPv6 and uses an inefficient HOST() cast in all lookups. As of 1.4 you can use GenericIPAddressField for IPv6, but the casting problem remains.

In addition to the basic IPAddressField replacement a CIDR and MACADDR field have been added. This library also provides a manager that allows for advanced IP based lookup directly in the ORM.

Dependencies

Current version of code is targeting Django 1.3-1.4 support, as this relies heavily on ORM internals supporting multiple versions is especially tricky. IPy is used for the same reasons. ipaddr is being considered, but the conversion hinges on the related projects conversion to ipaddr.

Getting started

Make sure netfields is in your PYTHONPATH, then simply use the following:

from netfields import InetAddressField, NetManager

class Example(models.Model):
    inet = InetAddressField()
    # ...

    objects = NetManager()

The package also provides CidrAddressField and a MACAddressField. NetManager is required for the extra lookups to be available. Lookups for INET and CIDR database types will be handled differently than when running vanilla Django. All lookups are case-insensitive and text based lookups are avoided whenever possible. In addition to Django’s default lookup types the following have been added.

  • __net_contained

  • __net_contained_or_equal

  • __net_contains

  • __net_contains_or_equals

These correspond with the operators from http://www.postgresql.org/docs/9.1/interactive/functions-net.html

netfields does not have to be in INSTALLED_APPS.

Similar projects

https://bitbucket.org/onelson/django-ipyfield tries to solve some of the same issues as this library. However, instead of supporting just postgres via the proper fields types the ipyfield currently uses a VARCHAR(39) as a fake unsigned 64 bit number in its implementation.

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-netfields-0.1.tar.gz (5.9 kB view hashes)

Uploaded Source

Supported by

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