mirror of
				https://github.com/django/django.git
				synced 2025-10-31 01:25:32 +00:00 
			
		
		
		
	Thanks Carl Meyer for the review. Squashed commit of the following: commit4f290bdb60Author: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Wed Feb 13 21:21:30 2013 +0100 Used '0:00' instead of 'UTC' which doesn't always exist in Oracle. Thanks Ian Kelly for the suggestion. commit01b6366f3cAuthor: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Wed Feb 13 13:38:43 2013 +0100 Made tzname a parameter of datetime_extract/trunc_sql. This is required to work around a bug in Oracle. commit924a144ef8Author: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Wed Feb 13 14:47:44 2013 +0100 Added support for parameters in SELECT clauses. commitb4351d2890Author: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Mon Feb 11 22:30:22 2013 +0100 Documented backwards incompatibilities in the two previous commits. commit91ef84713cAuthor: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Mon Feb 11 09:42:31 2013 +0100 Used QuerySet.datetimes for the admin's date_hierarchy. commit0d0de288a5Author: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Mon Feb 11 09:29:38 2013 +0100 Used QuerySet.datetimes in date-based generic views. commit9c0859ff7cAuthor: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Sun Feb 10 21:43:25 2013 +0100 Implemented QuerySet.datetimes on Oracle. commit68ab511a4fAuthor: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Sun Feb 10 21:43:14 2013 +0100 Implemented QuerySet.datetimes on MySQL. commit22d52681d3Author: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Sun Feb 10 21:42:29 2013 +0100 Implemented QuerySet.datetimes on SQLite. commitf6800fd04cAuthor: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Sun Feb 10 21:43:03 2013 +0100 Implemented QuerySet.datetimes on PostgreSQL. commit0c829c23f4Author: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Sun Feb 10 21:41:08 2013 +0100 Added datetime-handling infrastructure in the ORM layers. commit104d82a777Author: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Mon Feb 11 10:05:55 2013 +0100 Updated null_queries tests to avoid clashing with the __second lookup. commitc01bbb3235Author: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Sun Feb 10 23:07:41 2013 +0100 Updated tests of .dates(). Replaced .dates() by .datetimes() for DateTimeFields. Replaced dates with datetimes in the expected output for DateFields. commit50fb7a5246Author: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Sun Feb 10 21:40:09 2013 +0100 Updated and added tests for QuerySet.datetimes. commita8451a5004Author: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Sun Feb 10 22:34:46 2013 +0100 Documented the new time lookups and updated the date lookups. commit29413eab2bAuthor: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Sun Feb 10 16:15:49 2013 +0100 Documented QuerySet.datetimes and updated QuerySet.dates.
		
			
				
	
	
		
			84 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			84 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| from __future__ import absolute_import
 | |
| 
 | |
| import datetime
 | |
| 
 | |
| from django.test import TestCase
 | |
| 
 | |
| from .models import Article, Comment, Category
 | |
| 
 | |
| 
 | |
| class DateTimesTests(TestCase):
 | |
|     def test_related_model_traverse(self):
 | |
|         a1 = Article.objects.create(
 | |
|             title="First one",
 | |
|             pub_date=datetime.datetime(2005, 7, 28, 9, 0, 0),
 | |
|         )
 | |
|         a2 = Article.objects.create(
 | |
|             title="Another one",
 | |
|             pub_date=datetime.datetime(2010, 7, 28, 10, 0, 0),
 | |
|         )
 | |
|         a3 = Article.objects.create(
 | |
|             title="Third one, in the first day",
 | |
|             pub_date=datetime.datetime(2005, 7, 28, 17, 0, 0),
 | |
|         )
 | |
| 
 | |
|         a1.comments.create(
 | |
|             text="Im the HULK!",
 | |
|             pub_date=datetime.datetime(2005, 7, 28, 9, 30, 0),
 | |
|         )
 | |
|         a1.comments.create(
 | |
|             text="HULK SMASH!",
 | |
|             pub_date=datetime.datetime(2005, 7, 29, 1, 30, 0),
 | |
|         )
 | |
|         a2.comments.create(
 | |
|             text="LMAO",
 | |
|             pub_date=datetime.datetime(2010, 7, 28, 10, 10, 10),
 | |
|         )
 | |
|         a3.comments.create(
 | |
|             text="+1",
 | |
|             pub_date=datetime.datetime(2005, 8, 29, 10, 10, 10),
 | |
|         )
 | |
| 
 | |
|         c = Category.objects.create(name="serious-news")
 | |
|         c.articles.add(a1, a3)
 | |
| 
 | |
|         self.assertQuerysetEqual(
 | |
|             Comment.objects.datetimes("article__pub_date", "year"), [
 | |
|                 datetime.datetime(2005, 1, 1),
 | |
|                 datetime.datetime(2010, 1, 1),
 | |
|             ],
 | |
|             lambda d: d,
 | |
|         )
 | |
|         self.assertQuerysetEqual(
 | |
|             Comment.objects.datetimes("article__pub_date", "month"), [
 | |
|                 datetime.datetime(2005, 7, 1),
 | |
|                 datetime.datetime(2010, 7, 1),
 | |
|             ],
 | |
|             lambda d: d
 | |
|         )
 | |
|         self.assertQuerysetEqual(
 | |
|             Comment.objects.datetimes("article__pub_date", "day"), [
 | |
|                 datetime.datetime(2005, 7, 28),
 | |
|                 datetime.datetime(2010, 7, 28),
 | |
|             ],
 | |
|             lambda d: d
 | |
|         )
 | |
|         self.assertQuerysetEqual(
 | |
|             Article.objects.datetimes("comments__pub_date", "day"), [
 | |
|                 datetime.datetime(2005, 7, 28),
 | |
|                 datetime.datetime(2005, 7, 29),
 | |
|                 datetime.datetime(2005, 8, 29),
 | |
|                 datetime.datetime(2010, 7, 28),
 | |
|             ],
 | |
|             lambda d: d
 | |
|         )
 | |
|         self.assertQuerysetEqual(
 | |
|             Article.objects.datetimes("comments__approval_date", "day"), []
 | |
|         )
 | |
|         self.assertQuerysetEqual(
 | |
|             Category.objects.datetimes("articles__pub_date", "day"), [
 | |
|                 datetime.datetime(2005, 7, 28),
 | |
|             ],
 | |
|             lambda d: d,
 | |
|         )
 |