Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In django queries are done on the model object, its well <a href="https://docs.djangoproject.com/en/dev/topics/db/queries/" rel="nofollow">documented</a>. The queries or querysets are lazy and when they execute they generally return a list of dict, each dict in the list contains the <code>field</code> followed by the <code>value</code> eg: <code>[{'user':'albert','country':'US and A :) ','description':'my description'},....]</code>.</p> <p>All possible source,destination combinations for every user?</p> <p>I think you will have to use a <a href="https://docs.djangoproject.com/en/dev/topics/db/queries/#lookups-that-span-relationships" rel="nofollow">reverse relation ship</a> to get this done eg:</p> <pre><code>my_joined_query = User.objects.values('user','source__country','source__description','destination__country') </code></pre> <p>notice that i'm using the smaller case name of the models <code>Source</code> and <code>Destination</code> which have <code>ForeignKey</code> relationship with <code>User</code> this will <strong>join all the three tabels</strong> go through the documentation its rich. </p> <p><strong>Edit:</strong></p> <p>To make an inner join you will have to tell the query, this can be simply achieved by using <code>__isnull=False</code> on the reverse model name:</p> <pre><code>my_innerjoined_query = User.objects.filter(source__isnull=False,destination__isnull=False) </code></pre> <p>This should do a inner join on all the tables.</p> <p>Then you can select what you want to display by using <code>values</code> as earlier.</p> <p>hope that helps. :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload