Reputation: 157
Say I have a model with a field as such:
begin_date = models.DateTimeField(blank=True)
Whenever I want to add a date using a string, for example, '2020-06-15T11:00'
it gives me the RuntimeWarning: received a naive datetime while time zone support is active
.
So what's the proper way of adding date to a model in Django?
Upvotes: 2
Views: 1039
Reputation: 477676
If you add a 'Z'
suffix, you specify the datetime in UTC, for the ISO 8601 standard [Django-doc]:
'2020-06-15T11:00Z'
You can however also pass a datetime
object:
from datetime import datetime
from pytz import UTC
datetime(2020, 6, 15, 11, 00, tzinfo=UTC)
Upvotes: 3