File tree Expand file tree Collapse file tree 1 file changed +5
-4
lines changed Expand file tree Collapse file tree 1 file changed +5
-4
lines changed Original file line number Diff line number Diff line change @@ -661,17 +661,18 @@ class IPAddressField(CharField):
661
661
'invalid' : _ ('Enter a valid IPv4 or IPv6 address.' ),
662
662
}
663
663
664
- def __init__ (self , protocol = 'both' , unpack_ipv4 = False , ** kwargs ):
664
+ def __init__ (self , protocol = 'both' , ** kwargs ):
665
665
self .protocol = protocol .lower ()
666
- self .unpack_ipv4 = unpack_ipv4
666
+ self .unpack_ipv4 = ( self . protocol == 'both' )
667
667
super (IPAddressField , self ).__init__ (** kwargs )
668
- validators , error_message = ip_address_validators (protocol , unpack_ipv4 )
668
+ validators , error_message = ip_address_validators (protocol , self . unpack_ipv4 )
669
669
self .validators .extend (validators )
670
670
671
671
def to_internal_value (self , data ):
672
672
if data and ':' in data :
673
673
try :
674
- return clean_ipv6_address (data , self .unpack_ipv4 )
674
+ if self .protocol in ('both' , 'ipv6' ):
675
+ return clean_ipv6_address (data , self .unpack_ipv4 )
675
676
except DjangoValidationError :
676
677
self .fail ('invalid' , value = data )
677
678
You can’t perform that action at this time.
0 commit comments