Re: Need to combine 2 QuerySets without losing ability to order_by foreign key afterwards

2011-02-11 Thread Tom Evans
On Fri, Feb 11, 2011 at 9:19 PM, Shawn Milochik wrote: > On Fri, Feb 11, 2011 at 4:15 PM, Tom Evans wrote: >> >> Have a read of this: >> >> http://www.secnetix.de/olli/Python/lambda_functions.hawk >> > > That's funny -- I did a quick Google search

Re: Need to combine 2 QuerySets without losing ability to order_by foreign key afterwards

2011-02-11 Thread Shawn Milochik
On Fri, Feb 11, 2011 at 4:15 PM, Tom Evans wrote: > > Have a read of this: > > http://www.secnetix.de/olli/Python/lambda_functions.hawk > That's funny -- I did a quick Google search and that's one I found also. I chose to give a quick sample instead of sending the link

Re: Need to combine 2 QuerySets without losing ability to order_by foreign key afterwards

2011-02-11 Thread Tom Evans
On Fri, Feb 11, 2011 at 9:06 PM, kyleduncan wrote: > I dont understand what the x is, but thank you so much for fixing this > for me in a matter of minutes! Have a read of this: http://www.secnetix.de/olli/Python/lambda_functions.hawk Cheers Tom -- You received

Re: Need to combine 2 QuerySets without losing ability to order_by foreign key afterwards

2011-02-11 Thread Shawn Milochik
On Fri, Feb 11, 2011 at 4:06 PM, kyleduncan wrote: > I dont understand what the x is, but thank you so much for fixing this > for me in a matter of minutes! > You're welcome. The 'key' kwarg to the sort function expects a value. Instead of giving it a single value,

Re: Need to combine 2 QuerySets without losing ability to order_by foreign key afterwards

2011-02-11 Thread kyleduncan
this seems to work: results = sorted(results, key=lambda x: x.user.last_login, reverse=True) I dont understand what the x is, but thank you so much for fixing this for me in a matter of minutes! On Feb 11, 8:36 pm, Shawn Milochik wrote: > Something like this: > > key =

Re: Need to combine 2 QuerySets without losing ability to order_by foreign key afterwards

2011-02-11 Thread Shawn Milochik
On Fri, Feb 11, 2011 at 3:59 PM, kyleduncan wrote: > Thank you! Not sure how to work it just yet though. do I replace x > with user?  i tried this: > > results = results.sort(key=lambda x: x.last_login, reverse=True) > > and got an error  that the Profile object

Re: Need to combine 2 QuerySets without losing ability to order_by foreign key afterwards

2011-02-11 Thread kyleduncan
Thank you! Not sure how to work it just yet though. do I replace x with user? i tried this: results = results.sort(key=lambda x: x.last_login, reverse=True) and got an error that the Profile object didn't have the attribute last_login On Feb 11, 8:36 pm, Shawn Milochik

Re: Need to combine 2 QuerySets without losing ability to order_by foreign key afterwards

2011-02-11 Thread Shawn Milochik
Something like this: key = lambda x: x.last_login -- 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

Need to combine 2 QuerySets without losing ability to order_by foreign key afterwards

2011-02-11 Thread kyleduncan
Hi, I have the following code: results = list(results.filter(**location_distance_kwargs)) for trip in possible_trips: try: trip = Trip.objects.get(id=trip.id, **trip_kwargs) profile = Profile.objects.get(user=trip.user) if profile not in results:

Re: order_by foreign key

2009-02-16 Thread Alex Gaynor
On Mon, Feb 16, 2009 at 1:52 PM, jeffhg58 wrote: > > I have seen other posts on this topic but it seems that it was on the > old trunk. I am using > Django version 1.1 and I am unable to sort by foreign key > > When I try and execute the following query > >

order_by foreign key

2009-02-16 Thread jeffhg58
I have seen other posts on this topic but it seems that it was on the old trunk. I am using Django version 1.1 and I am unable to sort by foreign key When I try and execute the following query Result.objects.select_related().order_by('StatusId.Status') I get 0 rows retrieved. Is that the

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: 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')

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??