README.rst 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 PostgreSQL net related fields for
  5. Django. In Django pre 1.4 the built in ``IPAddressField`` does not support IPv6
  6. and uses an inefficient ``HOST()`` cast in all lookups. As of 1.4 you can use
  7. ``GenericIPAddressField`` for IPv6, but the casting problem remains.
  8. In addition to the basic ``IPAddressField`` replacement a ``CIDR`` and
  9. ``MACADDR`` field have been added. This library also provides a manager that
  10. allows for advanced IP based lookup directly in the ORM.
  11. Dependencies
  12. ------------
  13. Current version of code is targeting Django 1.3-1.4 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 package 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/9.1/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. https://docs.djangoproject.com/en/dev/releases/1.4/#extended-ipv6-support is also relevant
  44. .. _11442: http://code.djangoproject.com/ticket/11442
  45. .. _811: http://code.djangoproject.com/ticket/811
  46. Similar projects
  47. ----------------
  48. https://bitbucket.org/onelson/django-ipyfield tries to solve some of the same
  49. issues as this library. However, instead of supporting just postgres via the proper
  50. fields types the ipyfield currently uses a ``VARCHAR(39)`` as a fake unsigned 64 bit
  51. number in its implementation.