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 Version 1

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 (last modified by djbug)

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 (1)

comment:1 by djbug, 10 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top