Custom Django model fields for ipv4 and ipv6 addresses

Registered by Magnus Eide

Djangos IPAddressField does not work properly with ipv6, and operations such as "IN" and "BETWEEN" are broken.

Also, django don't support all the operations seen on http://www.postgresql.org/docs/8.3/interactive/functions-net.html

A solution may be to create custom fields for inet and cidr. This will make ipv6 and regular django field operators work.

The second problem may be solved by a custom manager that supports more field operators than the default one. It will probably by hackish, but the hacks will be consentrated in one place instead of many.

Blueprint information

Status:
Not started
Approver:
None
Priority:
Undefined
Drafter:
None
Direction:
Needs approval
Assignee:
None
Definition:
New
Series goal:
None
Implementation:
Unknown
Milestone target:
None

Related branches

Sprints

Whiteboard

An attempt has been made made to create a custom backend that subclasses the psycopg2 backend and works around the llimitations in Django's IP fields. Through this attempt is has become clear that only a field will not be a good enough solution. However a custom Manger with an appropriate WhereNode and a custom IP field with a modified get_db_prep_lookup might work.

See http://gist.github.com/348914 for the current version at this attempt. base.py is a dropin db backend that needs to be used with and IPAddressField from fields.py, manager.py is a standalone attempt at setting up a manager+custom field for proper lookups. Currently http://gist.github.com/348914#file_manager.py seems to be in working shape, remaining work should probably include formfields for all the fields, proper tests and validation of for instance MAC values.

(https://gist.github.com/348914/395eff3d96d4bd16c0e63955c9dfa9b9b23853ec contains the backend based version)

Since Django to the best of my knowledge does not have an easy way to distinguish how queries are made on various backends, adding custom lookup types is probably the way to go. In conformance with Django way of handling these types of new features a standalone django-postgres-inet-lookup is probably the way to go.

However looking at how geo-django is built should provide (and has) provided good clues as how to implement this.

(?)

Work Items

This blueprint contains Public information 
Everyone can see this information.

Subscribers

No subscribers.