Opened 10 years ago

Last modified 10 years ago

#24281 closed Cleanup/optimization

auto_now & auto_now_add ignore TIME_ZONE / USE_TZ settings for DateField — at Initial Version

Reported by: djbug Owned by: nobody
Component: Documentation Version: dev
Severity: Normal Keywords: timezone
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

auto_now & auto_now_add ignore TIME_ZONE / USE_TZ settings for DateField

https://github.com/django/django/blob/1.7/django/db/models/fields/__init__.py#L1146

def pre_save(self, model_instance, add):

if self.auto_now or (self.auto_now_add and add):

value = datetime.date.today()
setattr(model_instance, self.attname, value)
return value

else:

return super(DateField, self).pre_save(model_instance, add)

Instead of datetime.date.today(), this should use timezone.now().date().

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top