Looking at the source for django…
class CommaSeparatedIntegerField(CharField):
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)
Check out that regex validator. Looks like as long as you give it a list of integers and commas, django won’t complain.
You can define it just like a charfield basically:
class Foo(models.Model):
int_list = models.CommaSeparatedIntegerField(max_length=200)
And populate it like this:
f = Foo(int_list="1,2,3,4,5")