Regrettably the IPAddressField implementation is not what I expect :-(.
Is there by any chance, the possibilty to have a solution that works for
ipv4 *and* ipv6 in the near future ?
I know you have tons of things to do before the release of the
outstanding 1.1.
So far, I do have very scarce knowledge of the underlying framework
(quiet in fact none at all), but from what I see now, this can't be
that challenging. Feel free to correct me ;-)
First of all I would use a normal unsigned integer in all backends and
let IPy do the *math*.
In django/forms/fields.py I would rename ipv4_re to ip_re with the
following modifications for the beginning:
re.compile(r'^(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}|([:0-9a-fA-F]+)$')
Then I would add a clean method that uses IPy to check vor a valid
ip-address, never mind the version.
def clean(self, value):
if self.required and not value:
raise ValidationError(self.error_messages['required'])
...
try:
IPy.IP(value)
except ValueError:
raise ValidationError(self.error_messages['...'] % {...})
In django/db/models/fields/__init__.py it seems that I have to use the
to_python method to do the checks....
And surely get rid of the kwargs['max_length'] = 15 assignment.
return new_value
So the IPAddressField would not change, maybe it would be useful to have
a member that gives the answer which ip version is used.
gfk
See ticket #811: http://code.djangoproject.com/ticket/811
Regards,
Ian
Barring the actual state, I do not have a good feeling about this patch.
Foremost, I think IPy really should be used, last but not lease to
follow DRY.
From a design point of view, I think the IPAddressField should rule all
ip versions.
Certainly it is not a bad idea, to have IPv4 and IPv6 versions of this
field.
gfk
Adi, if you mean this:
* attachment ipv6-9781.diff added.
IPv6 patch for trunk, revision 9781
yes you are right, there was added an IP6AddressField that handles the
ipv6 stuff.
The existing IPAddressField further on cares about the IPv4.
But that was exactly my point. It should be possible to let the
IPAddressField handle any version, and to have specific
AddressFields for the varying versions.
Beyond that, the arguments of using IPy, and using an positive int in
the backends are still there.
gfk
Hello,The way I read the comments on the ticket the last patch supports IPv4and IPv6 address.See: http://code.djangoproject.com/ticket/811#comment:16
Adi, if you mean this:
* attachment ipv6-9781.diff added.
IPv6 patch for trunk, revision 9781
yes you are right, there was added an IP6AddressField that handles the
ipv6 stuff.
The existing IPAddressField further on cares about the IPv4.
> and I guess the IPAddressField didn't get changed because the IPv6
> addresses need a longer database field,
> so changing the IPAddressField would break backward compatibility.
Generally i do agree with the *usefulness* of not breaking compatibiltiy.
But on the other hand, I think that correcting this weird handling of IP
addresses would legitimate the cut.
Because the handling of IP addresses is not that intrinsic, like for
example the orm, it should be possible to cope with the change,
and to get rid of this ward.
gfk
I'm afraid Oracle only supports 38 digits of precision for numeric
columns. Since this requires 39, it won't work.
Thanks,
Ian
Right now we have an IPAddress field. People are using it. You *cannot*
break their code and requiring the database field to be changed does
just that. So, no. This would have to be a differently named field. We
might well deprecate the existing version, but breaking existing code
just because it's "neat" is not an option.
Regards,
Malcolm