Django 4.2: Trouble with DateTimeField Default Values in Timezone-aware Queries
I'm confused about I'm stuck on something that should probably be simple... I'm working on a Django 4.2 application and working with an scenario with setting default values for a `DateTimeField` in models when handling timezone-aware queries. I have a `created_at` field in my model that I want to default to the current time in UTC but I keep getting a wrong timezone offset when I try to filter records based on this field. Here's a snippet of my model: ```python from django.db import models from django.utils import timezone class Event(models.Model): title = models.CharField(max_length=255) created_at = models.DateTimeField(default=timezone.now) ``` When I try to filter events created today using the following query: ```python events_today = Event.objects.filter(created_at__date=timezone.now().date()) ``` I get results that seem to include events from the previous day. I suspect it has something to do with the timezone awareness of the `created_at` field and the local timezone settings. I've confirmed that my timezone settings in `settings.py` are set as follows: ```python TIME_ZONE = 'UTC' USE_TZ = True ``` Additionally, I tried using `timezone.localtime()` to convert the time before filtering, but that didn't help either. The database is PostgreSQL, and I’ve also checked that the server time is set correctly. Despite all this, events from the previous day still appear in the results. Has anyone encountered this scenario or could provide insight into how to properly handle timezone-aware queries in Django? It feels like I might be missing something fundamental here. Has anyone else encountered this? The stack includes Python and several other technologies.