On Sat, Aug 23, 2008 at 11:50 AM, Benjamin Buch <[EMAIL PROTECTED]> wrote:

>
> Am 22.08.2008 um 23:15 schrieb Garrett Garcia:
>
> How about:
>
> songs = Recording.objects.filter(song__title__startswith='R',
> represents_song=True)
>
> http://www.djangoproject.com/documentation/db-api/#filter-kwargs
>
> "Multiple parameters are joined via AND in the underlying SQL statement."
>
> - Garrett
>
>
> The problem I still see with this is that this is a query set containing
> recordings, not songs.
> Let's assume there can be several recordings that represent the song and
> thus can have "represents_song=True".
> If you had the query from above,
>
> songs = Recording.objects.filter(song__title__startswith='R',
> represents_song=True),
>
> how would you display the songs in the template in a way that the songs and
> recordings would order like this:
>
> song_1_title
>   song_1_representative_recording_1
>   song_1_representative_recording_2
>   song_1_representative_recording_3
>
> song_2_title
>   song_2_representative_recording_1
>   song_2_representative_recording_2
>
> ...
>
> ?
>
> -benjamin
>


You're right.  Using the word "recordings" as the variable is less
confusing.  I was only using "songs" because that's what you called it in
your original question.

 recordings = Recording.objects.filter(song__title__startswith='R',
represents_song=True).order_by(song__title)

You can then loop through the list of recordings in the template.  Use the
ifchanged tag to only print the song title once for each song.  Also, it
seems to me that you WANT to return a list of recordings, not songs, since
you'll be accessing the mp3 object of each recording.

Filtering this way is not a workaround, it's the simplest and easiest way to
do it.



> >
>

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