README.rst 2.1 KB

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