Den 16/06/2014 kl. 20.49 skrev jose alejandro hernandez rosales 
<karna...@gmail.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

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

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/E4F1BEA0-6621-4E4B-B322-B26B62F4DD3C%40cederstrand.dk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to