Django: making raw SQL query, passing multiple/repeated params?
Posted
by AP257
on Stack Overflow
See other posts from Stack Overflow
or by AP257
Published on 2010-05-31T14:48:11Z
Indexed on
2010/05/31
14:53 UTC
Read the original article
Hit count: 742
django
Hopefully this should be a fairly straightforward question, I just don't know enough about Python and Django to answer it.
I've got a raw SQL query in Django that takes six different parameters, the first two of which (centreLat and centreLng) are each repeated:
query = "SELECT units, (SQRT(((lat-%s)*(lat-%s)) + ((lng-%s)*(lng-%s)))) AS distance FROM places WHERE lat<%s AND lat>%s AND lon<%s AND lon>%s ORDER BY distance;"
params = [centreLat,centreLng,swLat,neLat,swLng,neLng]
places = Place.objects.raw(query, params)
How do I structure the params
object and the query
string so they know which parameters to repeat and where?
© Stack Overflow or respective owner