diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py
index 254e685..019714a 100644
a
|
b
|
class DateTimeField(DateField):
|
998 | 998 | # local time. This won't work during DST change, but we can't |
999 | 999 | # do much about it, so we let the exceptions percolate up the |
1000 | 1000 | # call stack. |
1001 | | warnings.warn("DateTimeField received a naive datetime (%s)" |
1002 | | " while time zone support is active." % value, |
| 1001 | warnings.warn("DateTimeField %s.%s received a naive datetime " |
| 1002 | "(%s) while time zone support is active." % |
| 1003 | (self.model.__name__, self.name, value), |
1003 | 1004 | RuntimeWarning) |
1004 | 1005 | default_timezone = timezone.get_default_timezone() |
1005 | 1006 | value = timezone.make_aware(value, default_timezone) |
… |
… |
class DateTimeField(DateField):
|
1053 | 1054 | # For backwards compatibility, interpret naive datetimes in local |
1054 | 1055 | # time. This won't work during DST change, but we can't do much |
1055 | 1056 | # about it, so we let the exceptions percolate up the call stack. |
1056 | | warnings.warn("DateTimeField received a naive datetime (%s)" |
1057 | | " while time zone support is active." % value, |
| 1057 | warnings.warn("DateTimeField %s.%s received a naive datetime (%s)" |
| 1058 | " while time zone support is active." % |
| 1059 | (self.model.__name__, self.name, value), |
1058 | 1060 | RuntimeWarning) |
1059 | 1061 | default_timezone = timezone.get_default_timezone() |
1060 | 1062 | value = timezone.make_aware(value, default_timezone) |
diff --git a/docs/topics/i18n/timezones.txt b/docs/topics/i18n/timezones.txt
index 5ed60d0..875c618 100644
a
|
b
|
code: :func:`~django.utils.timezone.now`,
|
431 | 431 | Finally, in order to help you locate code that needs upgrading, Django raises |
432 | 432 | a warning when you attempt to save a naive datetime to the database:: |
433 | 433 | |
434 | | RuntimeWarning: DateTimeField received a naive datetime (2012-01-01 00:00:00) while time zone support is active. |
| 434 | RuntimeWarning: DateTimeField Model.field_name received a naive datetime |
| 435 | (2012-01-01 00:00:00) while time zone support is active. |
435 | 436 | |
436 | 437 | During development, you can turn such warnings into exceptions and get a |
437 | 438 | traceback by adding the following to your settings file:: |
438 | 439 | |
439 | 440 | import warnings |
440 | 441 | warnings.filterwarnings( |
441 | | 'error', r"DateTimeField received a naive datetime", |
442 | | RuntimeWarning, r'django\.db\.models\.fields') |
| 442 | 'error', r"DateTimeField [\w_][\w_\d]+\.[\w_][\w_\d]+ received " |
| 443 | "a naive datetime", RuntimeWarning, r'django\.db\.models\.fields') |
443 | 444 | |
444 | 445 | Fixtures |
445 | 446 | -------- |
diff --git a/tests/timezones/tests.py b/tests/timezones/tests.py
index d2f67d9..329dca7 100644
a
|
b
|
class NewDatabaseTests(TestCase):
|
274 | 274 | Event.objects.create(dt=dt) |
275 | 275 | self.assertEqual(len(recorded), 1) |
276 | 276 | msg = str(recorded[0].message) |
277 | | self.assertTrue(msg.startswith("DateTimeField received a naive datetime")) |
| 277 | self.assertTrue(msg.startswith("DateTimeField Event.dt received " |
| 278 | "a naive datetime")) |
278 | 279 | event = Event.objects.get() |
279 | 280 | # naive datetimes are interpreted in local time |
280 | 281 | self.assertEqual(event.dt, dt.replace(tzinfo=EAT)) |
… |
… |
class NewDatabaseTests(TestCase):
|
287 | 288 | Event.objects.create(dt=dt) |
288 | 289 | self.assertEqual(len(recorded), 1) |
289 | 290 | msg = str(recorded[0].message) |
290 | | self.assertTrue(msg.startswith("DateTimeField received a naive datetime")) |
| 291 | self.assertTrue(msg.startswith("DateTimeField Event.dt received " |
| 292 | "a naive datetime")) |
291 | 293 | event = Event.objects.get() |
292 | 294 | self.assertEqual(event.dt, datetime.datetime(2011, 9, 1, tzinfo=EAT)) |
293 | 295 | |
… |
… |
class NewDatabaseTests(TestCase):
|
300 | 302 | Event.objects.create(dt=dt) |
301 | 303 | self.assertEqual(len(recorded), 1) |
302 | 304 | msg = str(recorded[0].message) |
303 | | self.assertTrue(msg.startswith("DateTimeField received a naive datetime")) |
| 305 | self.assertTrue(msg.startswith("DateTimeField Event.dt received " |
| 306 | "a naive datetime")) |
304 | 307 | event = Event.objects.get() |
305 | 308 | # naive datetimes are interpreted in local time |
306 | 309 | self.assertEqual(event.dt, dt.replace(tzinfo=EAT)) |
… |
… |
class NewDatabaseTests(TestCase):
|
314 | 317 | Event.objects.create(dt=dt) |
315 | 318 | self.assertEqual(len(recorded), 1) |
316 | 319 | msg = str(recorded[0].message) |
317 | | self.assertTrue(msg.startswith("DateTimeField received a naive datetime")) |
| 320 | self.assertTrue(msg.startswith("DateTimeField Event.dt received " |
| 321 | "a naive datetime")) |
318 | 322 | event = Event.objects.get() |
319 | 323 | # microseconds are lost during a round-trip in the database |
320 | 324 | # naive datetimes are interpreted in local time |
… |
… |
class NewDatabaseTests(TestCase):
|
401 | 405 | self.assertEqual(len(recorded), 3) |
402 | 406 | for warning in recorded: |
403 | 407 | msg = str(warning.message) |
404 | | self.assertTrue(msg.startswith("DateTimeField received a naive datetime")) |
| 408 | self.assertTrue(msg.startswith("DateTimeField Event.dt " |
| 409 | "received a naive datetime")) |
405 | 410 | |
406 | 411 | @skipUnlessDBFeature('has_zoneinfo_database') |
407 | 412 | def test_query_datetime_lookups(self): |