11Django PostgreSQL Netfields
22===========================
33
4- .. image :: https://secure.travis-ci.org/jimfunk/django-postgresql-netfields.png
5-
64This project is an attempt at making proper PostgreSQL net related fields for
75Django. In Django pre 1.4 the built in ``IPAddressField `` does not support IPv6
86and uses an inefficient ``HOST() `` cast in all lookups. As of 1.4 you can use
97``GenericIPAddressField `` for IPv6, but the casting problem remains.
108
11- In addition to the basic ``IPAddressField `` replacement a ``CIDR `` and
12- a ``MACADDR `` field have been added. This library also provides a manager that
13- allows for advanced IP based lookup directly in the ORM.
9+ In addition to the basic ``IPAddressField `` replacement, ``InetAddressField ``,
10+ a ``CidrAddressField `` a ``MACAddressField ``, and a ``MACAddress8Field `` have
11+ been added. This library also provides a manager that allows for advanced IP
12+ based lookups directly in the ORM.
1413
1514In Python, the values of the IP address fields are represented as types from
1615the ipaddress _ module. In Python 2.x, a backport _ is used. The MAC address
17- field is represented as an EUI type from the netaddr _ module.
16+ fields are represented as EUI types from the netaddr _ module.
1817
1918.. _ipaddress : https://docs.python.org/3/library/ipaddress.html
2019.. _backport : https://pypi.python.org/pypi/ipaddress/
@@ -23,8 +22,7 @@ field is represented as an EUI type from the netaddr_ module.
2322Dependencies
2423------------
2524
26- Current version of code is targeting Django >= 1.8 support, as this relies
27- heavily on ORM internals and supporting multiple versions is especially tricky.
25+ This module requires ``Django >= 1.11 ``, ``psycopg2 ``, and ``netaddr ``.
2826
2927Installation
3028------------
@@ -81,6 +79,19 @@ in network utilities and by network administrators (``00:11:22:aa:bb:cc``).
8179 inet = MACAddressField()
8280 # ...
8381
82+ ``MACAddress8Field `` will store values in PostgreSQL as type ``MACADDR8 ``. In
83+ Python, the value will be represented as a ``netaddr.EUI `` object. As with
84+ ``MACAddressField ``, the representation is the common one
85+ (``00:11:22:aa:bb:cc:dd:ee ``).
86+
87+ .. code-block :: python
88+
89+ from netfields import MACAddress8Field, NetManager
90+
91+ class Example (models .Model ):
92+ inet = MACAddress8Field()
93+ # ...
94+
8495 For ``InetAddressField `` and ``CidrAddressField ``, ``NetManager `` is required
8596for the extra lookups to be available. Lookups for ``INET `` and ``CIDR ``
8697database types will be handled differently than when running vanilla Django.
@@ -185,6 +196,16 @@ Database Functions
185196| trunc(``T ``) | Trunc | ``T `` | set last 3 bytes to zero |
186197+--------------------------------+------------------+----------------------+----------------------------------------------------------------+
187198
199+ **MACAddress8Field Functions **
200+
201+ +--------------------------------+------------------+----------------------+----------------------------------------------------------------+
202+ | Postgres Function | Django Function | Return Type | Description |
203+ +================================+==================+======================+================================================================+
204+ | trunc(``T ``) | Trunc | ``T `` | set last 5 bytes to zero |
205+ +--------------------------------+------------------+----------------------+----------------------------------------------------------------+
206+ | macaddr8_set7bit(``T ``) | Macaddr8Set7bit | ``T `` | set 7th bit to one. Used to generate link-local IPv6 addresses |
207+ +--------------------------------+------------------+----------------------+----------------------------------------------------------------+
208+
188209Indexes
189210'''''''
190211
@@ -224,12 +245,6 @@ For earlier versions of Django, a custom migration can be used to install an ind
224245 # ...
225246 ]
226247
227- Errata
228- ------
229-
230- * In Django < 1.9.6 types returned in ArrayFields are strings and not ipaddress types. See
231- https://code.djangoproject.com/ticket/25143
232-
233248 Related Django bugs
234249-------------------
235250
0 commit comments