lib models_extends py from django db models fields import URLField IPA

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
lib/models_extends.py
from django.db.models.fields import URLField, IPAddressField
class IPorURLField(IPAddressField, URLField):
empty_strings_allowed = False
def __init__(self, verbose_name=None, name=None, verify_exists=True, **kwargs):
kwargs['max_length'] = kwargs.get('max_length', 200)
#IPorURLField.__init__(self, verbose_name, name, **kwargs)
def get_internal_type(self):
return "IPorURLAddressField"
def formfield(self, **kwargs):
defaults = {'form_class': forms.IPorURLField}
defaults.update(kwargs)
return super(IPorURLAddressField, self).formfield(**defaults)