1
0
mirror of https://github.com/django/django.git synced 2025-11-07 07:15:35 +00:00

Fixed #8556: added a useful formfield to CommaSeparatedIntegerField. gkelly, mattmcc, and kratorius all contributed portions of this patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8682 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jacob Kaplan-Moss
2008-08-28 20:58:10 +00:00
parent fe8e00ae06
commit a41ca9c9e2
4 changed files with 55 additions and 1 deletions

View File

@@ -394,7 +394,17 @@ class CharField(Field):
# TODO: Maybe move this into contrib, because it's specialized.
class CommaSeparatedIntegerField(CharField):
pass
def formfield(self, **kwargs):
defaults = {
'form_class': forms.RegexField,
'regex': '^[\d,]+$',
'max_length': self.max_length,
'error_messages': {
'invalid': _(u'Enter only digits separated by commas.'),
}
}
defaults.update(kwargs)
return super(CommaSeparatedIntegerField, self).formfield(**defaults)
ansi_date_re = re.compile(r'^\d{4}-\d{1,2}-\d{1,2}$')