Hi folks,
I have several rather large SQL queries that I want to return a QS. I
need to put a subselect in the tables part of "extra" to achieve this.
The example below I can refactor to be more conventional but I have
other examples where I need to use this construct.
It *seems* since QS refactor's trunk merge (r.7483 on MySQL 5.0.41)
that *my* code is broken, throwing a MySQL error. It did work before.
ProgrammingError at /
(1103, "Incorrect table name '(SELECT DISTINCT
f.id\n\t\tFROM
films_film AS f\n\t\tJOIN films_listing AS l ON l.film_id =
f.id\n\t
\tWHERE l'")
Below is the custom manager:
class FilmsManager(models.Manager):
"""custom methods for film data"""
def new_films(self):
"""return 10 new films"""
return self.extra(
tables=["""(SELECT DISTINCT
f.id
FROM films_film AS f
JOIN films_listing AS l ON l.film_id =
f.id
WHERE l.starttime > NOW( )
AND f.year !=0000
ORDER BY year DESC
LIMIT 0 , 10) as topten"""],
where=['
films_film.id =
topten.id']
)
Has anything changed in the way these queries are assembled in pure
SQL? How would you go about debugging this?
Best wishes and thanks!