#10970 closed (fixed)
auto_now_add for DateField evaluetes to datetime.datetime instance
Reported by: | Ivan Gromov | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.0 |
Severity: | Keywords: | DateField, auto_now_add | |
Cc: | summer.is.gone@…, cyberj@…, jjlorenzo@… | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I've set auto_now_add to DateField, but it evaluates to datetime.datetime instance rather than datetime.date.
Here some example:
code in models.py
class Order(models.Model): created = models.DateField(auto_now_add=True)
and manage.py shell output:
In [1]: from app.models import Order In [3]: o = Order() In [4]: o.save() In [5]: o.created Out[5]: datetime.datetime(2009, 5, 1, 2, 53, 32, 280919)
I'm using django-1.0.2-final
Attachments (3)
Change History (15)
comment:1 by , 16 years ago
comment:2 by , 16 years ago
Patch needs improvement: | set |
---|
This patch doesn't work as DateTimeField
relies on inhering this method.
comment:3 by , 16 years ago
Has patch: | set |
---|---|
Needs tests: | set |
comment:4 by , 15 years ago
Surely datetime.date.today() is more concise than datetime.datetime.now().date() - is there a good reason why the latter was selected?
by , 15 years ago
Attachment: | auto_now_patch.diff added |
---|
comment:5 by , 15 years ago
Nope, there wasn't reason to use datetime.now().date()
instead datetime.date.today()
. I've updated patch, thank you.
comment:6 by , 15 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:7 by , 15 years ago
Cc: | added |
---|---|
Needs tests: | unset |
Patch needs improvement: | unset |
This bug remains an issue for applications like http://code.google.com/p/django-reversion/ because it takes a serialized datetime object for datefield with auto_now_add
.
I've updated patch for r12846 and tests are OK
comment:8 by , 14 years ago
See #14037 for a manifestation of this bug when using Django's own serialization machinery)
comment:9 by , 14 years ago
Cc: | added |
---|
by , 14 years ago
Attachment: | 10970.diff added |
---|
Patch updated to r14002 (test fixed to actually fail before the fix and updated to unittest)
comment:10 by , 14 years ago
milestone: | → 1.3 |
---|---|
Triage Stage: | Accepted → Ready for checkin |
comment:11 by , 14 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Checked out to revision #10650, bug still there