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 and that's one I found
> also. I chose to give a quick sample instead of sending the link
> because I thought an example relevant to the OP might be easier to
> grok.
>
> Interestingly, the Google search didn't let me easily find the
> official Python docs on it, or I missed it.
>
> Shawn
>

Heh :)

I checked out a couple of them, the secnetix one to me seemed the best
written, and clearly indicated the what, how and why of lambda
functions. Looked a lot like an extended version of yours!

For me, "python lambda" had the python docs at 2nd in the list.

Cheers

Tom

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



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
because I thought an example relevant to the OP might be easier to
grok.

Interestingly, the Google search didn't let me easily find the
official Python docs on it, or I missed it.

Shawn

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



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 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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



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, you can pass a function.

So, you could have done this:

def return_last_login(record):

return record.user.last_login

Then: my_list.sort(key = return_last_login(x))

But you can use a shortcut and use the 'lambda' keyword, which just
returns an anonymous function.

So, these two are equivalent:

my_function = return_last_login

my_function = lambda x: x.user.last_login

I hope this helps.

Shawn

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



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 = 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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



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 didn't have the attribute
> last_login


If some of the objects in your list have the attribute last_login and
others do not then you'll have to make a custom cmp function and pass
it to the sort call.

If not, and each object in your list has a user which has a
last_login, then replace x.last_login with x.user.last_login and it
should work.

The 'x' is insignificant. You can replace it in both cases with
'profile' if it makes your code more readable.

Shawn

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



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  wrote:
> 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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



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:
results.append(profile)
except Trip.DoesNotExist:
pass

In the above, "results" is a GeoQuerySet of Profile objects, converted
to a list so that i can append more profiles in the code below... I
then check a totally separate array (of Trip objects) against their
own kwargs, then for each match I pull out the Profile object
associated with the User of each Trip, and append it to the "results"
list, if it's not already there (to avoid duplication).

As an aside: I first tried appending profiles without having converted
"results" to a list, but append() couldnt be used on the "results"
querySet. so i forced "results" to be a list using the list()
function, which made it possible to append the second profiles onto
the end of results.

All seemed ok so far. However, i finally wanted to order the profiles
in results by "user__last_login" (profiles have a ForeignKey of user,
and user has a property "last login". When i tried doing this using
python's sorted() function it didnt work as it seemed unable to delve
beyond the user foreign key and into the last_login attribute. this is
what failed:

results = sorted(results, key=attrgetter('user__last_login'),
reverse=True)

as obviously "user__last_login" doesnt exist at this stage as an
attribute. i tried "user.last_login" and varous combinations, but
nothing worked. at the moment the code just reads like this, which
works:

results = sorted(results, key=attrgetter('user'), reverse=True)

any idea how, after merging two query sets by turning them into lists,
i can sort them by an attribute of a foreign key for the objects in
the list?

Thanks in advance to anybody who can help!

Kyle

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



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
>
> Result.objects.select_related().order_by('StatusId.Status')
>
>  I get 0 rows retrieved.
>
> Is that the correct way to order by foreign keys?
>
> Here are the models in question
>
> class Result( models.Model):
>TestName = models.CharField( max_length=100)
>TestVersion =  models.CharField( max_length=50,
>null=True)
>ExecutionStartDate =   models.DateTimeField( verbose_name = "Start
> Date",
>null=True)
>StatusId = models.ForeignKey( Status,
>verbose_name = "Status",
>db_column='StatusId',
>
> related_name="OverallStatus")
>AutoStatusId = models.ForeignKey( Status,
>verbose_name = "Status",
>db_column='AutoStatusId',
>related_name="AutoStatus")
>PrintVerifyStatusId =  models.ForeignKey( Status,
>verbose_name = "Status",
>
> db_column='PrintVerifyStatusId',
>
> related_name="PrintVerifyStatus")
>ImageVerifyStatusId =  models.ForeignKey( Status,
>verbose_name = "Status",
>
> db_column='ImageVerifyStatusId',
>
> related_name="ImageVerifyStatus")
>ExecutionTime =models.DecimalField( max_digits=10,
>decimal_places=4)
>StationId =models.ForeignKey( Station,
>verbose_name = "Station",
>db_column='StationId')
>SubmitDate =   models.DateTimeField( verbose_name="Submit
> Date",
>null=True)
>Owner =models.CharField( max_length=100)
>ProjectId =models.ForeignKey( Project,
>verbose_name = "Project",
>db_column='ProjectId')
>PhaseId =  models.ForeignKey( Phase,
>verbose_name = "Phase",
>db_column='PhaseId')
>TestTypeId =   models.ForeignKey( Type,
>verbose_name = "Test
> Type",
>db_column='TestTypeId')
>UserInterventionFlag = models.BooleanField( default=False)
>CurrentFlag =  models.BooleanField( default=True)
>ActiveFlag =   models.BooleanField( default=True)
>objects =  models.Manager() # The default manager.
>
>config_objects =   ResultManager()
>
>
> class Status( models.Model):
>Status =   models.CharField( max_length=100)
>AutoFlag = models.BooleanField()
>
> Thanks,
> Jeff
> >
>
http://docs.djangoproject.com/en/dev/ref/models/querysets/#order-by-fieldstake
a look at the example of doing related filtering and note that it uses
the __ syntax.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



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 correct way to order by foreign keys?

Here are the models in question

class Result( models.Model):
TestName = models.CharField( max_length=100)
TestVersion =  models.CharField( max_length=50,
null=True)
ExecutionStartDate =   models.DateTimeField( verbose_name = "Start
Date",
null=True)
StatusId = models.ForeignKey( Status,
verbose_name = "Status",
db_column='StatusId',
 
related_name="OverallStatus")
AutoStatusId = models.ForeignKey( Status,
verbose_name = "Status",
db_column='AutoStatusId',
related_name="AutoStatus")
PrintVerifyStatusId =  models.ForeignKey( Status,
verbose_name = "Status",
 
db_column='PrintVerifyStatusId',
 
related_name="PrintVerifyStatus")
ImageVerifyStatusId =  models.ForeignKey( Status,
verbose_name = "Status",
 
db_column='ImageVerifyStatusId',
 
related_name="ImageVerifyStatus")
ExecutionTime =models.DecimalField( max_digits=10,
decimal_places=4)
StationId =models.ForeignKey( Station,
verbose_name = "Station",
db_column='StationId')
SubmitDate =   models.DateTimeField( verbose_name="Submit
Date",
null=True)
Owner =models.CharField( max_length=100)
ProjectId =models.ForeignKey( Project,
verbose_name = "Project",
db_column='ProjectId')
PhaseId =  models.ForeignKey( Phase,
verbose_name = "Phase",
db_column='PhaseId')
TestTypeId =   models.ForeignKey( Type,
verbose_name = "Test
Type",
db_column='TestTypeId')
UserInterventionFlag = models.BooleanField( default=False)
CurrentFlag =  models.BooleanField( default=True)
ActiveFlag =   models.BooleanField( default=True)
objects =  models.Manager() # The default manager.

config_objects =   ResultManager()


class Status( models.Model):
Status =   models.CharField( max_length=100)
AutoFlag = models.BooleanField()

Thanks,
Jeff
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



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;
> +-+--+--+-+-+---+
> | Field   | Type | Null | Key | Default | Extra |
> +-+--+--+-+-+---+
> | generic_info_id | int(11)  |  | PRI | 0   |   |
> +-+--+--+-+-+---+
>
> >>> gear = Gear.objects.order_by('-generic_info__hits')
> >>> print gear
> [snipped some]
> OperationalError: (1054, "Unknown column
> 'itemengine_gear.generic_info__hits' in 'order clause'")
>
> I can't believe I used this OnetoOne and populated a whole db around
> this model and it's broken.  Do you think this is a bug ?  Is there
> some way I can trick django and change the model to a regular foreign
> key without having to start everything over?
>
> Thanks.
>

It was a bug, ordering by foreign key fields was notoriously fragile before
queryset-refactor was merged into trunk.  I just tried your example on
current trunk and it works fine.  So I'd advise updating to a current SVN
checkout of Django.

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



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 | Null | Key | Default | Extra |
+-+--+--+-+-+---+
| generic_info_id | int(11)  |  | PRI | 0   |   |
+-+--+--+-+-+---+

>>> gear = Gear.objects.order_by('-generic_info__hits')
>>> print gear
Traceback (most recent call last):
  File "", line 1, in ?
  File "/usr/lib/python2.3/site-packages/django/db/models/query.py",
line 108, in __repr__
return repr(self._get_data())
  File "/usr/lib/python2.3/site-packages/django/db/models/query.py",
line 483, in _get_data
self._result_cache = list(self.iterator())
  File "/usr/lib/python2.3/site-packages/django/db/models/query.py",
line 189, in iterator
cursor.execute("SELECT " + (self._distinct and "DISTINCT " or "")
+ ",".join(select) + sql, params)
  File "/usr/lib/python2.3/site-packages/django/db/backends/util.py",
line 18, in execute
return self.cursor.execute(sql, params)
  File "/usr/lib/python2.3/site-packages/MySQLdb/cursors.py", line
163, in execute
self.errorhandler(self, exc, value)
  File "/usr/lib/python2.3/site-packages/MySQLdb/connections.py", line
35, in defaulterrorhandler
raise errorclass, errorvalue
OperationalError: (1054, "Unknown column
'itemengine_gear.generic_info__hits' in 'order clause'")



I can't believe I used this OnetoOne and populated a whole db around
this model and it's broken.  Do you think this is a bug ?  Is there
some way I can trick django and change the model to a regular foreign
key without having to start everything over?

Thanks.




On May 29, 6:10 pm, "Richard Dahl" <[EMAIL PROTECTED]> wrote:
> 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 relationships ahead of time.
>
> Try to do it without the select_related to see if you can get the query to
> execute.  I know this will mean an additional hit on the db to access the
> related model, but I can't think of anything else.
>
> hth,
>
> -richard
>
> On 5/29/08, robstar <[EMAIL PROTECTED]> wrote:
>
>
>
> > 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.select_related().order_by('-generic_info__hits')
> > >>> print gear
>
> > Traceback (most recent call last):
> > File "", line 1, in ?
> > File "/usr/lib/python2.3/site-packages/django/db/models/query.py",
> > line 108, in __repr__
> >return repr(self._get_data())
> > File "/usr/lib/python2.3/site-packages/django/db/models/query.py",
> > line 483, in _get_data
> >self._result_cache = list(self.iterator())
> > File "/usr/lib/python2.3/site-packages/django/db/models/query.py",
> > line 189, in iterator
> >cursor.execute("SELECT " + (self._distinct and "DISTINCT " or "")
> > + ",".join(select) + sql, params)
> > File "/usr/lib/python2.3/site-packages/django/db/backends/util.py",
> > line 18, in execute
> >return self.cursor.execute(sql, params)
> > File "/usr/lib/python2.3/site-packages/MySQLdb/cursors.py", line
> > 163, in execute
> >self.errorhandler(self, exc, value)
> > File "/usr/lib/python2.3/site-packages/MySQLdb/connections.py", line
> > 35, in defaulterrorhandler
> >raise errorclass, errorvalue
> > OperationalError: (1054, "Unknown column
> > 'itemengine_gear.generic_info__hits' in 'order clause'")
>
> >    The template chokes the same way trying to access the object...
> > I shouldn't have to change my code?
>
> > rob
>
> > On May 29, 4:16 pm, "Richard Dahl" <[EMAIL PROTECTED]> wrote:
> > >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')
>
> > > hth,
> > > -richard
>
> > > On 5/29/08, robstar <[EMAIL PROTECTED]> wrote:
>
> > > > 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 

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



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



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



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 relationships ahead of time.

Try to do it without the select_related to see if you can get the query to
execute.  I know this will mean an additional hit on the db to access the
related model, but I can't think of anything else.

hth,

-richard



On 5/29/08, robstar <[EMAIL PROTECTED]> wrote:
>
>
> 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.select_related().order_by('-generic_info__hits')
> >>> print gear
>
> Traceback (most recent call last):
> File "", line 1, in ?
> File "/usr/lib/python2.3/site-packages/django/db/models/query.py",
> line 108, in __repr__
>return repr(self._get_data())
> File "/usr/lib/python2.3/site-packages/django/db/models/query.py",
> line 483, in _get_data
>self._result_cache = list(self.iterator())
> File "/usr/lib/python2.3/site-packages/django/db/models/query.py",
> line 189, in iterator
>cursor.execute("SELECT " + (self._distinct and "DISTINCT " or "")
> + ",".join(select) + sql, params)
> File "/usr/lib/python2.3/site-packages/django/db/backends/util.py",
> line 18, in execute
>return self.cursor.execute(sql, params)
> File "/usr/lib/python2.3/site-packages/MySQLdb/cursors.py", line
> 163, in execute
>self.errorhandler(self, exc, value)
> File "/usr/lib/python2.3/site-packages/MySQLdb/connections.py", line
> 35, in defaulterrorhandler
>raise errorclass, errorvalue
> OperationalError: (1054, "Unknown column
> 'itemengine_gear.generic_info__hits' in 'order clause'")
>
>    The template chokes the same way trying to access the object...
> I shouldn't have to change my code?
>
> rob
>
> On May 29, 4:16 pm, "Richard Dahl" <[EMAIL PROTECTED]> wrote:
> > 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')
> >
> > hth,
> > -richard
> >
> > On 5/29/08, robstar <[EMAIL PROTECTED]> wrote:
> >
> >
> >
> > > 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??
> >
> > > results = Gear.objects.select_related().order_by(generic_info__hits)
> >
> > > I also tried putting the db name in there like I saw in some old
> > > examples:
> >
> > > results =
> > > Gear.objects.select_related().order_by(gcdb_generic_info__hits)
> >
> > > Both result in the field not being found..  Any ideas???  thanks!
> >
> > > rob
> >
>

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



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


hth,
-richard


On 5/29/08, robstar <[EMAIL PROTECTED]> wrote:
>
>
> 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??
>
> results = Gear.objects.select_related().order_by(generic_info__hits)
>
> I also tried putting the db name in there like I saw in some old
> examples:
>
> results =
> Gear.objects.select_related().order_by(gcdb_generic_info__hits)
>
>
> Both result in the field not being found..  Any ideas???  thanks!
>
> rob
>
> >
>

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



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

  results = Gear.objects.select_related().order_by(generic_info__hits)

I also tried putting the db name in there like I saw in some old
examples:

  results =
Gear.objects.select_related().order_by(gcdb_generic_info__hits)


Both result in the field not being found..  Any ideas???  thanks!

rob

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