Created
January 31, 2012 14:41
-
-
Save Enome/1710834 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.core.management import setup_environ | |
import settings | |
setup_environ(settings) | |
from django.db import connection | |
from apps.books.models import Book | |
books = Book.objects.raw( """ | |
select * | |
from books_book | |
where | |
genre_id in | |
(select genre_id | |
from books_book | |
where | |
id in (select book_id from books_bookrelation where user_id = 564 and connection = 2)) | |
or id in | |
(select book_id | |
from books_book_authors | |
where author_id in | |
(select author_id | |
from books_book_authors | |
where book_id in (select book_id from books_bookrelation where user_id = 564 and connection = 2))) | |
and id not in | |
(select book_id from books_bookrelation where user_id = 564 and connection = 2) | |
and cover is not null | |
limit 10 | |
offset 10 | |
""") | |
len(list(books)) | |
print 'test', connection.queries |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment