39👍
Yes, it can. It is debatable whether it should–there is a longstanding bug report: http://code.djangoproject.com/ticket/7609
8👍
For those looking to exclude the 0, it’s easy to write a validator for that.
def validate_nonzero(value):
if value == 0:
raise ValidationError(
_('Quantity %(value)s is not allowed'),
params={'value': value},
)
and then use it as such
fill_qty = models.PositiveIntegerField(
default=0,
validators=[MaxValueValidator(1000000), validate_nonzero]
)
- [Django]-Django {% static 'path' %} in javascript file
- [Django]-Django Deprecation Warning or ImproperlyConfigured error – Passing a 3-tuple to django.conf.urls.include() is not supported
- [Django]-How to select_related when using .get() in django?
6👍
Yes.
The model field reference says so. For completeness, also quoted here:
PositiveIntegerField
class PositiveIntegerField([**options])
Like an IntegerField, but must be either positive or zero (0). The value 0 is accepted for backward compatibility reasons.
- [Django]-How to get the common name for a pytz timezone eg. EST/EDT for America/New_York
- [Django]-How can I change the way a boolean prints in a django template?
- [Django]-Django request to find previous referrer
4👍
Well by the definition of a Positive Integer, it shouldn’t accept a zero value, but django actually considers it in the sense of none-negative number which is zero inclusive. So, Yes it can accept a zero value
- [Django]-ValueError: The field admin.LogEntry.user was declared with a lazy reference
- [Django]-Django migrate : doesn't create tables
- [Django]-'EntryPoints' object has no attribute 'get' – Digital ocean
3👍
Yes, "PositiveIntegerField" can contain "0" value.
For example, I defined the model "Point" as shown below:
# "myapp/models.py"
from django.db import models
class Point(models.Model):
points = models.PositiveIntegerField()
Then, run this command below:
python manage.py makemigrations && python manage.py migrate
Now, I opened "db.sqlite3" then as you can see, "CHECK("points" >= 0)" is set to "points" field which means "PositiveIntegerField" can contain "0" value:
- [Django]-Identify the changed fields in django post_save signal
- [Django]-Update to Django 1.8 – AttributeError: django.test.TestCase has no attribute 'cls_atomics'
- [Django]-How to make a POST simple JSON using Django REST Framework? CSRF token missing or incorrect