#24373 closed Uncategorized (fixed)
RegexValidator In ArrayField Not Running
Reported by: | David Muller | Owned by: | |
---|---|---|---|
Component: | contrib.postgres | Version: | 1.8alpha1 |
Severity: | Normal | Keywords: | ArrayField RegexValidator |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I am trying out Django 1.8's new ArrayField and was hoping to enforce RegexValidation on an array of CharFields. It appears, however, that the RegexValidator is not being run.
For the sake of simplicity, let's say I only wanted to accept numeric values in my CharFields. We'll also say that my save() method calls full_clean():
class TestModel(models.Model): names = ArrayField( models.CharField(max_length=100, blank=False, validators=[RegexValidator(r'^[0-9]*$')]), ) def save(self, *args, **kwargs): """ Raise ValidationError if a field doesn't pass validation. """ try: self.full_clean() except ValidationError: raise super(TestModel, self).save(*args, **kwargs)
No ValidationError is thrown, a TestModel record is created successfully:
In [2]: TestModel.objects.create(names=['no']) Out[2]: <TestModel: TestModel object>
Is not possible to add validators to the <base_field> of my ArrayField?
Thanks!
Change History (2)
comment:1 by , 10 years ago
Owner: | set to |
---|---|
Resolution: | → fixed |
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
In c490e410af086fa89f40d515505bba02a08168f3: