Opened 15 years ago
Closed 12 years ago
#12752 closed New feature (fixed)
validators should allow check against empty to be customized
Reported by: | Shaun Cutts | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.2-alpha |
Severity: | Normal | Keywords: | |
Cc: | shaun@… | Triage Stage: | Accepted |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I have a custom field, which sets up a correspondence between a numpy array and a postgres array. It mostly seems to be working. However, when I call .full_clean() on a model containing such a field, the validation code eventually calls:
django.db.models.fields.init.py(207)validate():
206 207 -> if not self.blank and value in validators.EMPTY_VALUES: 208 raise exceptions.ValidationError(self.error_messages['blank'])
Here, the numpy definition for equality snarls things, and I get:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
I suggest a django.db.models.Field
member is_empty
be added, which does value in validators.EMPTY_VALUES
by default, but can be overridden by a custom subclass.
Change History (6)
comment:1 by , 15 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → New feature |
comment:3 by , 13 years ago
UI/UX: | unset |
---|
comment:5 by , 12 years ago
From [22be90dd171dee], empty_values
is now a field attribute, and is customizable.
Is this sufficient to resolve your use case, or do you really need a custom method to achieve what you want?
Change UI/UX from NULL to False.