Giter Site home page Giter Site logo

crustymonkey / django-postgresql-netfields Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jimfunk/django-postgresql-netfields

1.0 3.0 0.0 164 KB

Proper INET and CIDR fields for Django running on PostgreSQL

License: BSD 3-Clause "New" or "Revised" License

Python 100.00%

django-postgresql-netfields's Introduction

Django PostgreSQL Netfields

This project is an attempt at making proper Django net related fields for Django Currently the built in IPAddressField does not support IPv6 and uses an inefficient HOST() cast in all lookups. Hopefully there experience from this project can lead to a resolution of these issues upstream.

In addition to the basic IPAddressField replacement a CIDR and MACADDR field have been added. Furthermore a customer Manager allows for access to all of PostgreSQL's INET operators.

Dependencies

Current version of code is targeting Django 1.2 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 page 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/8.3/interactive/functions-net.html

netfields does not have to be in INSTALLED_APPS.

Related Django bugs

  • 11442 - Postgresql backend casts inet types to text, breaks IP operations and IPv6 lookups.
  • 811 - IPv6 address field support.

django-postgresql-netfields's People

Contributors

adamcik avatar eide avatar key avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.