2👍
✅
As others have pointed out, null
doesn’t exist in python, None
is the way to represent null values. That said, there are several ways you could address your issue:
Option 1: Change your field definition to:
number_of_likes = models.IntegerField(default=0)
Option 2: If you don’t want to change the field, you could:
object.number_of_likes = int(object.number_of_likes) + 1 if object.number_of_likes else 1
Hope this helps
0👍
Just to check I did a python manage.py shell
and typed
>>> null
and got:
NameError: name 'null' is not defined
I don’t think there’s a null
, except when a None
is stored into the database.
- [Answered ]-How to redirect to another view with parameter in this example?
- [Answered ]-Pytz – timezone activated yet getting wrong time. Am I missing something?
- [Answered ]-Formset initial choice field
- [Answered ]-Trying to get the errors from a failed Stripe charge
- [Answered ]-Generate PDF from http request in Django
0👍
null may not have public availabilty but exists as a property when using models.Integerfield although Django docs has explicitly said that it is best to avoid using it with Charfield – https://docs.djangoproject.com/en/4.0/ref/models/fields/
- [Answered ]-Unable to match trailing slash after email address in url regex
- [Answered ]-Upload a specific file form Django/Python
- [Answered ]-Counting occurrences of a foreign key in a related queryset
- [Answered ]-{% block %} in {% blocktrans %}
Source:stackexchange.com