mirror of
https://github.com/django/django.git
synced 2025-08-04 10:59:45 +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
|
@ -91,6 +91,20 @@ query could also be written::
|
|||
>>> name_map = {'first': 'first_name', 'last': 'last_name', 'bd': 'birth_date', 'pk': 'id'}
|
||||
>>> Person.objects.raw('SELECT * FROM some_other_table', translations=name_map)
|
||||
|
||||
Index lookups
|
||||
-------------
|
||||
|
||||
``raw()`` supports indexing, so if you need only the first result you can
|
||||
write::
|
||||
|
||||
>>> first_person = Person.objects.raw('SELECT * from myapp_person')[0]
|
||||
|
||||
However, the indexing and slicing are not performed at the database level. If
|
||||
you have a big amount of ``Person`` objects in your database, it would be more
|
||||
efficient to limit the query at the SQL level::
|
||||
|
||||
>>> first_person = Person.objects.raw('SELECT * from myapp_person LIMIT 1')[0]
|
||||
|
||||
Deferring model fields
|
||||
----------------------
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue