Here are the examples of the python api django.forms.IPAddressField taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
2 Examples
3
Example 1
Project: django-any Source File: forms.py
@any_form_field.register(forms.IPAddressField)
def ipaddress_field_data(field, **kwargs):
"""
Return random value for IPAddressField
>>> result = any_form_field(forms.IPAddressField())
>>> type(result)
<type 'str'>
>>> from django.core.validators import ipv4_re
>>> import re
>>> re.match(ipv4_re, result) is not None
True
"""
choices = kwargs.get('choices')
if choices:
return random.choice(choices)
else:
nums = [str(xunit.any_int(min_value=0, max_value=255)) for _ in xrange(0, 4)]
return ".".join(nums)
0
Example 2
def formfield(self, **kwargs):
defaults = {'form_class': forms.IPAddressField}
defaults.update(kwargs)
return super(IPAddressField, self).formfield(**defaults)