If you want the date_created
field to store the correct date of creation, you can modify the default value with this: default=timezone.now().date()
The .date()
method returns the date portion of a DateTime object and this will set the date_created
field to "2023-03-01" (In your case - New DB Entry will require), which is the correct date of creation.
So you can try the code as per below:
class Submission(models.Model):
date_created = models.DateField(
default=timezone.now().date(),
blank=True,
)
datetime_created = models.DateTimeField(
default=timezone.now,
)
The reason of the date_created field is set to "2023-03-02
" is that the DateField type only stores the date, without the time information so when you set the default value to timezone.now
it will take the time zone information specified in your settings.py file.
As you have set the time zone to "US/Mountain" on settings.py
file, which is 7 hours behind UTC. Since the TIME_ZONE setting was set to "US/Mountain" when the data entry happens at 5 PM MST on 03/01/2023
, the actual date in UTC was 02/01/2023
(time difference between MST and UTC). This is the reason why the value for date_created was set to "2023-03-02
" for you.
You can check timezone converter