On Thu, Oct 23, 2008 at 10:44 AM, AndyB <[EMAIL PROTECTED]> wrote: > > >>> p.residentialunitmix_set.all().query.as_sql() > > (u'SELECT `tbl_ResidentialUnitMix`.`id`, > `tbl_ResidentialUnitMix`.`Planning-id`, > `tbl_ResidentialUnitMix`.`quantity`, > `tbl_ResidentialUnitMix`.`Bedrooms`, `tbl_ResidentialUnitMix`.`Type`, > `tbl_ResidentialUnitMix`.`Tenure` FROM `tbl_ResidentialUnitMix` WHERE > `tbl_ResidentialUnitMix`.`Planning-id` = %s ' , (82)) > > >>> p.residentialunitmix_set.select_related().query.as_sql() > > (u'SELECT `tbl_ResidentialUnitMix`.`id`, > `tbl_ResidentialUnitMix`.`Planning-id`, > `tbl_ResidentialUnitMix`.`quantity`, > `tbl_ResidentialUnitMix`.`Bedrooms`, `tbl_ResidentialUnitMix`.`Type`, > `tbl_ResidentialUnitMix`.`Tenure` FROM `tbl_ResidentialUnitMix` WHERE > `tbl_ResidentialUnitMix`.`Planning-id` = %s ' , (82)) > > Tenure is a foreign key to another tables. How come both queries are > identical? > > I am trying to sort by a field in the Tenure table and: > > residentialunitmix_set.select_related().order_by('tbl_lkp_ResidentialUnitMix_Tenure.sort') > > just gives an error. Looking at the queries explained why. > > (Apologies for the table names. It's a Django interface to something > developed in Access) >
You've rather jumped to the end problem without telling us the beginning (model definitions). Now it's maybe possible to puzzle out what's going on based on the queries alone, but why make it so hard on us? Ideally you'd whittle it down to a minimal example that illustrates the problem you are seeing (which by the way, you should spell out in as great a detail as is presented to you -- "just gives an error" is about as useless a description of a problem as "doesn't work"), but if you can't manage that at least post the models you're actually working with. On dpaste.com, not inline in the post, if they are big/involved enough that the email//groups interface will make them hard to read. Karen --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---