1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | from django.forms import RegexField
class RegexFormatField(RegexField):
def __init__(self, *args, **kwargs):
if 'format' in kwargs:
self.format = kwargs['format']
del kwargs['format']
super(RegexFormatField, self).__init__(*args, **kwargs)
def clean(self, value):
value = super(RegexFormatField, self).clean(value)
if self.format is not None:
value = self.format % self.regex.match(value).groupdict()
return value
|
More like this
- BRPhoneNumberWidget by semente 1 year, 9 months ago
- Simple Mobile Support by bahoo 2 years, 8 months ago
- Model field choices as a namedtuple by whiteinge 2 years, 2 months ago
- Widget for DateTime values on Geraldo Reports by marinho 4 years, 2 months ago
- Bitwise operator queryset filter by hgeerts@osso.nl 3 years, 1 month ago
Comments