mirror of
https://github.com/django/django.git
synced 2025-08-02 10:02:41 +00:00
Fixed #12806 -- Added an implementation of RawQuerySet.__getitem__
. Thanks, Bruno Renié.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12504 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
349827996b
commit
c4699b0b8a
5 changed files with 35 additions and 2 deletions
|
@ -185,4 +185,19 @@ class RawQueryTests(TestCase):
|
|||
self.assertEqual(normal_authors[index], raw_author)
|
||||
second_iterations += 1
|
||||
|
||||
self.assertEqual(first_iterations, second_iterations)
|
||||
self.assertEqual(first_iterations, second_iterations)
|
||||
|
||||
def testGetItem(self):
|
||||
# Indexing on RawQuerySets
|
||||
query = "SELECT * FROM raw_query_author ORDER BY id ASC"
|
||||
third_author = Author.objects.raw(query)[2]
|
||||
self.assertEqual(third_author.first_name, 'Bob')
|
||||
|
||||
first_two = Author.objects.raw(query)[0:2]
|
||||
self.assertEquals(len(first_two), 2)
|
||||
|
||||
try:
|
||||
Author.objects.raw(query)['test']
|
||||
self.fail('Index lookups should only accept int, long or slice')
|
||||
except TypeError:
|
||||
pass
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue