`django.db.models.fields.DateField(auto_now=True)` sets date as
`datetime.date.today()` (see
[here](https://github.com/django/django/blob/master/django/db/models/fields/__init__.py#L1246)).
This date is not localized with django and can be different from
`django.utils.timezone.now()` used in `DateTimeField`, if django and local
timzeones differ.
Suggestion:
Change `datetime.date.today()` to `django.utils.timezone.now().date()`
--
Ticket URL: <https://code.djangoproject.com/ticket/32320>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* resolution: => invalid
Old description:
> Hi.
>
> `django.db.models.fields.DateField(auto_now=True)` sets date as
> `datetime.date.today()` (see
> [here](https://github.com/django/django/blob/master/django/db/models/fields/__init__.py#L1246)).
> This date is not localized with django and can be different from
> `django.utils.timezone.now()` used in `DateTimeField`, if django and
> local timzeones differ.
>
> Suggestion:
> Change `datetime.date.today()` to `django.utils.timezone.now().date()`
New description:
Hi.
`django.db.models.fields.DateField(auto_now=True)` sets date as
`datetime.date.today()` (see
[https://github.com/django/django/blob/master/django/db/models/fields/__init__.py#L1246
here]). This date is not localized with django and can be different from
`django.utils.timezone.now()` used in `DateTimeField`, if django and local
timzeones differ.
Suggestion:
Change `datetime.date.today()` to `django.utils.timezone.now().date()`
--
Comment:
This is a
[https://docs.djangoproject.com/en/3.1/ref/models/fields/#django.db.models.DateField.auto_now_add
documented] behavior:
> ''"The `auto_now` and `auto_now_add` options will always use the date in
the default timezone at the moment of creation or update. If you need
something different, you may want to consider using your own callable
default or overriding `save()` instead of using `auto_now` or
`auto_now_add`; or using a `DateTimeField` instead of a `DateField` and
deciding how to handle the conversion from `datetime` to `date` at display
time."''
--
Ticket URL: <https://code.djangoproject.com/ticket/32320#comment:1>
Comment (by Mariusz Felisiak):
Also, unlike `DateTimeField`, `DateField` isn't timezone-aware. See a
[https://github.com/django/django/pull/4902#discussion_r33062456 pull
request thread] where the change you suggested was proposed.
--
Ticket URL: <https://code.djangoproject.com/ticket/32320#comment:2>