I have this form:
class NetworkInput(forms.Form):
IP = forms.GenericIPAddressField()
Netmask = forms.IntegerField()
The users should be able to enter an IPv4 or an IPv6 address. Depending of the IP version the validation of Netmask should look like this:
import ipcalc
IP = ipcalc.IP(IP)
if IP.version() == 4:
if Netmask > 29:
raise ValidationError(u'%s is not big enough' % value)
else:
if Netmask > 125:
raise ValidationError(u'%s is not big enough' % value)
But I don't know how to access the variable IP when validating the Netmask.