You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like a field, which if left blank is None, and otherwise behaves like IntegerField.
As a workaround, we made this class:
class NullableIntegerField(IntegerField):
"""
An IntegerField where the field can be null if the input data is an empty
string.
"""
def process_formdata(self, valuelist):
if valuelist:
if valuelist[0] == '':
self.data = None
else:
try:
self.data = int(valuelist[0])
except ValueError:
self.data = None
raise ValueError(self.gettext('Not a valid integer value'))
Is there a better way to do this? Should I make some tests and a pull request?
The text was updated successfully, but these errors were encountered:
It's not the most intuitive thing in the world, but Optional is indeed what you want here, and for any other coercing validator. They are essentially required by default.
We have some plans for 2.0 to address this once and for all, without the slightly kludgey approach of using Optional.
I would like a field, which if left blank is None, and otherwise behaves like IntegerField.
As a workaround, we made this class:
Is there a better way to do this? Should I make some tests and a pull request?
The text was updated successfully, but these errors were encountered: