Re: Random ordering in Templates

2008-09-03 Thread Ludwig
Am I right that you have a one-to-many relationship between events and questions, with questions having a foreign key to events? Then you could add a method to your Event model class that returns you a random list of questions: class Event (model.Models): ... def questions(self): quest

Re: Random ordering in Templates

2008-09-03 Thread Cortland Klein
That looks like that should work! Thank you; I'll try this out when I get back from lunch. Sent from my iPhone On Sep 3, 2008, at 12:23 PM, Ludwig <[EMAIL PROTECTED]> wrote: > Am I right that you have a one-to-many relationship between events > and questions, with questions having a foreign k

Re: Random ordering in Templates

2008-09-03 Thread Cortland Klein
Yes, but I don't want to randomize he Events, but the Questions that belong to the events. On Sep 3, 2008, at 12:07 PM, Ludwig wrote: > There is nothing to stop you putting the order_by clause into a > generic view, like so: > > event_info = { > 'queryset' : Events.objects.order_by('?'),

Re: Random ordering in Templates

2008-09-03 Thread Ludwig
> > > Can I do that with a Generic View? > There is nothing to stop you putting the order_by clause into a generic view, like so: event_info = { 'queryset' : Events.objects.order_by('?'), } > > I'm using date_based.archive_index on an Event model which has many > Questions. > > On Sep 3, 2

Re: Random ordering in Templates

2008-09-03 Thread Cortland Klein
Can I do that with a Generic View? I'm using date_based.archive_index on an Event model which has many Questions. On Sep 3, 2008, at 11:40 AM, Karen Tracey wrote: > Why not just create the randomized list in the view and pass the > already-randomized list into the template? -- Cortland Kl

Random ordering in Templates

2008-09-03 Thread Cortland Klein
I've got the following in my template: > {% for question in event.question_set.order_by('?') %} And am getting the error "Could not parse the remainder: '('?')'". I'm trying to randomly iterate through these objects. Should I implement a custom filter, or is there an easier way to accomplish

Re: Random ordering in Templates

2008-09-03 Thread Ludwig
I think you are confusing two things here: querying the DB in views and displaying the output through templates. To get your object in a random order, add the order_by('?') to the view, see (see http://www.djangoproject.com/documentation/models/ordering/) Then you can just iterate through your (r

Re: Random ordering in Templates

2008-09-03 Thread Karen Tracey
On Wed, Sep 3, 2008 at 2:31 PM, Cortland Klein <[EMAIL PROTECTED]> wrote: > > I've got the following in my template: > > {% for question in event.question_set.order_by('?') %} > > And am getting the error "Could not parse the remainder: '('?')'". > You cannot call functions that take arguments fr