Oops, that should read "Cannot resolve keyword 'playlist_aggreation'
into field", even though I am messing with song aggregations and
playlist aggregations :)

On Jul 24, 11:29 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> Thanks!
>
> All of your workarounds involving filter didn't work, erroring with
> "Cannot resolve keyword 'song_aggregation' into field", which makes
> sense since I really wanted to go the other way around, I think.
>
> Anyways, after some munging with 'extra', as per your suggestion, I
> got it working!
>
> Thanks again,
> Eric
>
> On Jul 24, 10:36 pm, "Russell Keith-Magee" <[EMAIL PROTECTED]>
> wrote:
>
> > On 7/25/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> > > An analogous operation would be:
> > > playlist_aggregates = PlaylistAggregation.objects.order_by('-count')
> > > playlists = [p.playlist for p in playlist_aggregates]
>
> > The query itself looks like it's just a query over Playlist objects
> > where all the query terms relate to Playlist_aggregate, e.g.,
>
> > Playlist.objects.filter(playlist_aggregation__count=3)
>
> > The ordering issue is a little more difficult. Ideally, it sounds like
> > you want to be able to write:
>
> > Playlist.objects.all().order_by('playlist_aggregation.count')
>
> > but the query syntax doesn't currently support this; order_by isn't
> > taken into account when the joins are determined. This is part of a
> > task that Malcolm is currently looking at.
>
> > In the interim, there are a few workarounds. In the end, the argument
> > to order_by is just the SQL name of the attribute; it just happens
> > that for attributes on a model, the SQL name matches the attribute
> > name. However, you can use this to cheat a bit. If you substitute the
> > SQL name for the joined column, you can order by joined attribute - as
> > long as the related table is actually joined in the SQL query.
>
> > A normal Playlist.objects.all() query won't join Playlist_aggregation
> > - so you'll need to fake it. Either add a meaningless filter, like
> > filter(playlist_aggregation__count__gte=0) (which will join the table,
> > but not reject any rows), or use the 'extra' clause to manually add
> > the join required.
>
> > Yours,
> > Russ Magee %-)


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

Reply via email to