Re: order_by foreign key problem

2008-05-30 Thread Karen Tracey
On Fri, May 30, 2008 at 6:09 PM, robstar <[EMAIL PROTECTED]> wrote: > > Thanks for your help Richard.. taking out the select_related() > results in the same problem. Isn't a OnetoOneField just a fancy name > wrapper for a foreign key?? > > mysql> describe itemengine_gear; > +-+-

Re: order_by foreign key problem

2008-05-30 Thread robstar
Thanks for your help Richard.. taking out the select_related() results in the same problem. Isn't a OnetoOneField just a fancy name wrapper for a foreign key?? mysql> describe itemengine_gear; +-+--+--+-+-+---+ | Field | Type |

Re: order_by foreign key problem

2008-05-29 Thread Johannes Dollinger
Wah, nevermind .. Am 30.05.2008 um 01:27 schrieb Johannes Dollinger: > >> Should this work?? >> >> results = Gear.objects.select_related().order_by >> (generic_info__hits) > > Quotes are missing: > > Gear.objects.select_related().order_by('generic_info__hits') > > > > > > > --~--~-

Re: order_by foreign key problem

2008-05-29 Thread Johannes Dollinger
> Should this work?? > > results = Gear.objects.select_related().order_by(generic_info__hits) Quotes are missing: Gear.objects.select_related().order_by('generic_info__hits') --~--~-~--~~~---~--~~ You received this message because you are subscribed to the

Re: order_by foreign key problem

2008-05-29 Thread Richard Dahl
I am not sure what is going on, however I wonder if it has something to do with the OneToOne relationship, I do not use onetoone myself but notice in the following from the db-api documentation: Note that the select_related() QuerySet method recursively prepopulates the cache of all one-to-many re

Re: order_by foreign key problem

2008-05-29 Thread robstar
Oops, I had the ' ' in there somewhere in all my different iterations of trying to make this work .. so the query works, but I can't access the object in the template, or from the shell for that matter. Does something change by doing this type of query? On the shell: >>> gear = Gear.objects.se

Re: order_by foreign key problem

2008-05-29 Thread robstar
Oops, I had the ' ' in there somewhere in all my different iterations of trying to make this work .. so the query works, but I can't access the object in the template, or from the shell for that matter. Does something change by doing this type of query? On the shell: >>> gear = Gear.objects.se

Re: order_by foreign key problem

2008-05-29 Thread Richard Dahl
http://www.djangoproject.com/documentation/db-api/ contains the info you want. Try this: Gear.objects.select_related().order_by('generic_info__hits') you could also set the order_by in the Meta of Item to hits and then you could just do: Gear.objects.select_related().order_by('generic_info') ht

order_by foreign key problem

2008-05-29 Thread robstar
Hey guys, I read through some of the threads here, but still can't get this simple scenario to work.. DB name: gcdb class Item(models.Model): hits= models.IntegerField(default=0) class Gear(models.Model): generic_info= models.OneToOneField(Item) Should this work?? res