README.rst 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. Django PostgreSQL Netfields
  2. ===========================
  3. .. image:: https://secure.travis-ci.org/adamcik/django-postgresql-netfields.png
  4. This project is an attempt at making proper Django net related fields for
  5. Django Currently the built in ``IPAddressField`` does not support IPv6 and uses
  6. an inefficient ``HOST()`` cast in all lookups. Hopefully there experience from
  7. this project can lead to a resolution of these issues upstream.
  8. In addition to the basic ``IPAddressField`` replacement a ``CIDR`` and
  9. ``MACADDR`` field have been added. Furthermore a customer Manager allows for
  10. access to all of PostgreSQL's INET operators.
  11. Dependencies
  12. ------------
  13. Current version of code is targeting Django 1.2 support, as this relies heavily
  14. on ORM internals supporting multiple versions is especially tricky. ``IPy`` is
  15. used for the same reasons. ``ipaddr`` is being considered, but the conversion
  16. hinges on the related projects conversion to ``ipaddr``.
  17. Getting started
  18. ---------------
  19. Make sure ``netfields`` is in your ``PYTHONPATH``, then simply use the
  20. following::
  21. from netfields import InetAddressField, NetManager
  22. class Example(models.Model):
  23. inet = InetAddressField()
  24. # ...
  25. objects = NetManager()
  26. The page also provides ``CidrAddressField`` and a ``MACAddressField``.
  27. ``NetManager`` is required for the extra lookups to be available. Lookups for
  28. ``INET`` and ``CIDR`` database types will be handled differently than when
  29. running vanilla Django. All lookups are case-insensitive and text based
  30. lookups are avoided whenever possible. In addition to Django's default lookup
  31. types the following have been added.
  32. * ``__net_contained``
  33. * ``__net_contained_or_equal``
  34. * ``__net_contains``
  35. * ``__net_contains_or_equals``
  36. These correspond with the operators from
  37. http://www.postgresql.org/docs/8.3/interactive/functions-net.html
  38. ``netfields`` does not have to be in ``INSTALLED_APPS``.
  39. Related Django bugs
  40. -------------------
  41. * 11442_ - Postgresql backend casts inet types to text, breaks IP operations and IPv6 lookups.
  42. * 811_ - IPv6 address field support.
  43. .. _11442: http://code.djangoproject.com/ticket/11442
  44. .. _811: http://code.djangoproject.com/ticket/811