<div>Hi Puneeth<br></div><div></div><div>select_related() follows all relationships and pre-caches any foreign key values so that complex trees can be fetched in a single query. However, this isn’t always a good idea, so the depth argument control how many “levels” the select-related behavior will traverse.</div>
<div></div><div>I could have write the query for you but if you refer this doc link <a href="http://www.djangoproject.com/documentation/models/select_related/">http://www.djangoproject.com/documentation/models/select_related/</a> and try with yourself then will be good as you are trying to learn Django.</div>
<div></div><div>Thanks</div><div><br></div><div class="gmail_quote">On Wed, May 6, 2009 at 11:21 AM, Puneet Aggarwal <span dir="ltr">&lt;<a href="mailto:look4puneet@gmail.com">look4puneet@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Hello All,<br><br>I am trying to learn django and write a small application. I am facing issue in executing a join with django. <br>
I am able to find a work around by executing a raw SQL query using cursor. But that have problem that I need to access fields using<br>
&quot;object.0&#39; or &#39;object.1&#39;  which is too verbose and error prone.<br><br>Is there better way of doing the same thing or executing joins using Django models.<br><br>here is my table structure <br><br>table 1 : Company<br>

id = IntField<br>name = CharField<br><br>table 2 : Schmes<br>id = Int field<br>Name = CharFiled<br>comp_id = ForeignKey (company)<br><br>table 3 : Price <br><br>scheme_id = ForeignKey(Schemes)<br>price          = CharField()<br>

Date          = DateTimeField()<br><br>I want to execute a query on the price table where I can select the price of all the schemes for the specified company. <br><br>something like this if I write SQL : <br><br>select price from Price, Schemes, Company where Price.scheme_id = Scheme.id and Scheme.comp_id = Company.id and Company.id = 1.  <br>

<br>Thanks,<br><font color="#888888">Puneet<br><br><br>
</font><br>_______________________________________________<br>
BangPypers mailing list<br>
<a href="mailto:BangPypers@python.org">BangPypers@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/bangpypers" target="_blank">http://mail.python.org/mailman/listinfo/bangpypers</a><br>
<br></blockquote></div><br><div><br clear="all"></div><div><br></div><div>-- <br></div><div>Praveen Kumar<br>+91 9739854134<br><a href="http://praveensunsetpoint.wordpress.com">http://praveensunsetpoint.wordpress.com</a><br>
Bangalore<br></div>