Conver sql to orm django

18 views
Skip to first unread message

jose alejandro hernandez rosales

unread,
Jun 16, 2014, 2:49:45 PM6/16/14
to django...@googlegroups.com
Hi , everyone i have a little problem, how do I convert this sql sentence to ORM?

SELECT * FROM CLIENTS
LEFT JOIN rutas ON
clientes.ruta_id = rutas.ID
LLEFT JOIN repartidores ON
clientes.ruta_id = repartidores.ruta_id

Erik Cederstrand

unread,
Jun 17, 2014, 2:41:04 AM6/17/14
to Django Users
This should work:

Client.objects.select_related('ruta').prefetch_related('ruta__repartidores')

But you should really post your model code so we can see how the foreign key and many-to-many relations are defined.

Erik
Reply all
Reply to author
Forward
0 new messages