urls/generic views/dict question.

0 views
Skip to first unread message

mail....@gmail.com

unread,
May 11, 2007, 12:14:36 PM5/11/07
to Django users
OK, I have song_dict, which gathers up songs:
song_dict = {
'queryset': Song.objects.all(),
'allow_empty': 'true',
}

Which I pass to the podcast and playlist.xml. Playlist.xml is picked
up by the flash player for folks who want to listen on-site:

(r'^radio/podcast.xml',
'django.views.generic.list_detail.object_list', dict(song_dict,
template_name="radio/podcast.xml")),
(r'^radio/playlist.xml',
'django.views.generic.list_detail.object_list', dict(song_dict,
template_name="radio/playlist.xml")),

Podcast.xml does a reverse sort on pub date, which works nicely for
the podcast. No problems there. The problem is the playlist. The
number of songs are overloading it a bit, so what I'd like to do is a
random slice of 30 songs or so.

So my question is, do I need another dict, or can I slice and sort on
song_dict for the playlist only?

Malcolm Tredinnick

unread,
May 12, 2007, 12:34:29 AM5/12/07
to django...@googlegroups.com

If you're wanting to use a different queryset, then you at least need to
change the 'queryset' key in the song_dict dictionary. That seems so
obvious that I'm pretty sure I don't understand the question you're
really asking. Could you ask it in another way or give an example of
what you've tried that doesn't work?

Regards,
Malcolm


mail....@gmail.com

unread,
May 14, 2007, 10:42:02 AM5/14/07
to Django users
Sorry I was unclear...
I'm currently using the same song_dict for both podcast and
playlist.xml, which is 'queryset': Song.objects.all(),
That's fine for the podcast. In the template I reverse sort it on
pub_date, and it's perfect.
But for playlist I want something like: 'queryset':
Song.objects.all().order_by('?')[:30] as I don't want all of the
objects, and I need a random sample.

So, my question is, do I need to define a second dict for playlist, or
can I somehow modify song_dict in the URL line to just grab a random
30 items instead of all of them?

On May 11, 11:34 pm, Malcolm Tredinnick <malc...@pointy-stick.com>
wrote:

Dmitry Shevchenko

unread,
May 14, 2007, 12:44:39 PM5/14/07
to django...@googlegroups.com
I think you can write something like this:

(r'^radio/playlist.xml','django.views.generic.list_detail.object_list',
dict(dict(queryset=Song.objects.order_by('?')[:30],allow_empty=true),
template_name="radio/playlist.xml"))

Regards, Dmitry Shevchenko.

Reply all
Reply to author
Forward
0 new messages