[BangPypers] Joins with Django
praveen.python.plone at gmail.com
Wed May 6 12:01:17 CEST 2009
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.
I could have write the query for you but if you refer this doc link
http://www.djangoproject.com/documentation/models/select_related/ and try
with yourself then will be good as you are trying to learn Django.
On Wed, May 6, 2009 at 11:21 AM, Puneet Aggarwal <look4puneet at gmail.com>wrote:
> Hello All,
> I am trying to learn django and write a small application. I am facing
> issue in executing a join with django.
> 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
> "object.0' or 'object.1' which is too verbose and error prone.
> Is there better way of doing the same thing or executing joins using Django
> here is my table structure
> table 1 : Company
> id = IntField
> name = CharField
> table 2 : Schmes
> id = Int field
> Name = CharFiled
> comp_id = ForeignKey (company)
> table 3 : Price
> scheme_id = ForeignKey(Schemes)
> price = CharField()
> Date = DateTimeField()
> I want to execute a query on the price table where I can select the price
> of all the schemes for the specified company.
> something like this if I write SQL :
> select price from Price, Schemes, Company where Price.scheme_id = Scheme.id
> and Scheme.comp_id = Company.id and Company.id = 1.
> BangPypers mailing list
> BangPypers at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the BangPypers