21👍
✅
Don’t store it with the leading zeros. Format it on output instead:
(in view: value = 1)
{{ value|stringformat:"04d" }} # displays as 0001
2👍
I think you should use a CharField and do something like that :
try:
value = int(field)
# do something with value
except valueError:
# raise a ValidationError if you are in the *clean* methods of the form
# or raise an other exception
# or handle the error
# or just raise :-)
Source:stackexchange.com