I am in the process of upgrading my project from Django 1.8.2 to 1.9.7 and I'm getting this warning:
WARNINGS:
my_app.my_model.date_available: (fields.W161) Fixed default value provided.
HINT: It seems you set a fixed date / time / datetime value as default for this field. This may not be what you want.
If you want to have the current date as default, use `django.utils.timezone.now
Here's the line from my_app/models.py:
from django.utils import timezone
...
class my_model(models.Model):
...
datetime_released = models.DateTimeField(default=timezone.now() )
If I remove the parentheses and instead use:
datetime_released = models.DateTimeField(default=timezone.now )
The Django warning goes away. What's the difference between the two?
In another area of my project I am using timezone.now() in a queryset filter:
def date_available(self):
return self.filter(date_available__lte = timezone.now())
Here, if I remove the parentheses, an error is thrown:
TypeError: expected string or buffer
I can get both of these two work by adding/removing the parenthesis as required, but what is the difference between timezone.now() and timezone.now and why do they cause warnings/errors in these cases?