Opened 8 years ago
Closed 8 years ago
#29028 closed Cleanup/optimization (invalid)
Warning show up even use `django.utils.timezone.now`
| Reported by: | Windson yang | Owned by: | nobody |
|---|---|---|---|
| Component: | Uncategorized | Version: | 2.0 |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Create a new project like usual and create a model like this
from django.db import models
from django.utils import timezone
class Learn(models.Model):
title = models.CharField(max_length=50)
pay_time = models.DateTimeField(default=timezone.now())
after running migrations and run server, warning still show up
learn.Learn.pay_time: (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
This model already use django.utils.timezone.now, so I think we should not show this warning.
Change History (4)
comment:1 by , 8 years ago
| Type: | Uncategorized → Cleanup/optimization |
|---|
comment:2 by , 8 years ago
comment:4 by , 8 years ago
| Resolution: | → invalid |
|---|---|
| Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
I guess you didn't understand the warning. You should use
timezone.now(without parentheses) to use the time the object was created, otherwisetimezone.now()evaluates to the time when the web server loads themodels.pyfile. Should the message be clarified?