diff --git a/field_audit/models.py b/field_audit/models.py index b5381ae..5a8ec1d 100644 --- a/field_audit/models.py +++ b/field_audit/models.py @@ -1,4 +1,3 @@ -from datetime import datetime from enum import Enum from functools import wraps from itertools import islice @@ -6,6 +5,7 @@ from django.conf import settings from django.db import models, transaction from django.db.models import Expression +from django.utils import timezone from .const import BOOTSTRAP_BATCH_SIZE from .utils import class_import_helper @@ -197,7 +197,7 @@ def get_date(): This is the "getter" for default values of the ``AuditEvent.event_date`` field. """ - return datetime.utcnow() + return timezone.now() class AuditEvent(models.Model): diff --git a/tests/test_models.py b/tests/test_models.py index 870d7af..f62df12 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -1,5 +1,5 @@ from contextlib import ContextDecorator -from datetime import datetime, timedelta +from datetime import timedelta from enum import Enum from unittest.mock import ANY, Mock, patch @@ -10,6 +10,7 @@ from django.db.models import Case, When, Value from django.db.utils import IntegrityError, DatabaseError from django.test import TestCase, override_settings +from django.utils import timezone from field_audit.auditors import audit_dispatcher from field_audit.const import BOOTSTRAP_BATCH_SIZE @@ -295,7 +296,7 @@ def test_get_manager_uses_default_if_no_setting(self): def test_get_date(self): then = get_date() self.assertLess( - datetime.utcnow() - then, + timezone.now() - then, timedelta(seconds=1), )