summaryrefslogtreecommitdiff
path: root/tests/datetimes
diff options
context:
space:
mode:
authorJosh Smeaton <josh.smeaton@gmail.com>2016-03-05 23:05:47 +1100
committerJosh Smeaton <josh.smeaton@gmail.com>2016-05-18 20:14:58 +1000
commit2a4af0ea43512370764303d35bc5309f8abce666 (patch)
treeea0c9ba8051ae30df2f09e9a57e564e88d156489 /tests/datetimes
parent77b73e79a4750dcbfabc528bf00cad81ff5bb4d9 (diff)
Fixed #25774 -- Refactor datetime expressions into public API
Diffstat (limited to 'tests/datetimes')
-rw-r--r--tests/datetimes/models.py1
-rw-r--r--tests/datetimes/tests.py6
2 files changed, 7 insertions, 0 deletions
diff --git a/tests/datetimes/models.py b/tests/datetimes/models.py
index 47ce417e4c..2fcb72be09 100644
--- a/tests/datetimes/models.py
+++ b/tests/datetimes/models.py
@@ -8,6 +8,7 @@ from django.utils.encoding import python_2_unicode_compatible
class Article(models.Model):
title = models.CharField(max_length=100)
pub_date = models.DateTimeField()
+ published_on = models.DateField(null=True)
categories = models.ManyToManyField("Category", related_name="articles")
diff --git a/tests/datetimes/tests.py b/tests/datetimes/tests.py
index 447cbef99a..5bd3bc6d5f 100644
--- a/tests/datetimes/tests.py
+++ b/tests/datetimes/tests.py
@@ -153,3 +153,9 @@ class DateTimesTests(TestCase):
datetime.datetime(2005, 7, 30, 0, 0),
datetime.datetime(2005, 7, 29, 0, 0),
datetime.datetime(2005, 7, 28, 0, 0)])
+
+ def test_datetimes_disallows_date_fields(self):
+ dt = datetime.datetime(2005, 7, 28, 12, 15)
+ Article.objects.create(pub_date=dt, published_on=dt.date(), title="Don't put dates into datetime functions!")
+ with self.assertRaisesMessage(ValueError, "Cannot truncate DateField 'published_on' to DateTimeField"):
+ list(Article.objects.datetimes('published_on', 'second'))