I wrote one line wrong at:

4.)
>>> *p.altword_set.all().order_by('-votes')*
[<Altword: Leafy 3>, <Altword: Leafy 2>]


How do I write the correct syntax for ordering my list?




On Wednesday, August 7, 2013 11:59:38 PM UTC+2, Pepsodent Cola wrote:
>
> Hi,
> I have some database query ordering problems.
>
> 1.)
> On my webpage I see this output:
>
> * Option-1 = 18 votes
> * Option-2 = 50 votes
>
>
> 2.)
> *altword_list.html*
>
> <ul>
> {% for choice2 in poll.altword_set.all %}
> <!-- for choice2 in poll.altword_set.all().order_by('-votes') -->
>     <li>{{ choice2.rosword }} - {{ choice2.alt_ros_word }} - {{ 
> choice2.alt_transl_word }} - {{ choice2.articulate }} = {{ choice2.votes }} 
> votes</li>
> {% endfor %}
> </ul>
>
>
> 3.)
> I want my webpage to order the output by *most votes down to least votes*like 
> so:
>
> * Option-2 = 50 votes
> * Option-1 = 18 votes
>
>
> 4.)
> In Python shell I managed to accomplish that by doing like so:
>
> >>> p = Word.objects.get(pk=1)
> >>> p
> <Word: Page>
> >>> p.altword_set.all()
> [<Altword: Leafy 2>, <Altword: Leafy 3>]
>
> >>> *p.altword_set.all().order_by('votes')*
> [<Altword: Leafy 2>, <Altword: Leafy 3>]
>
>
> 5.)
> How come when I replace this:
>     {% for choice2 in poll.altword_set.all %}
> to this:
>     {% for choice2 in poll.altword_set.all().order_by('-votes')  %}
> then I get this error:
>
> Exception Type: TemplateSyntaxError  Exception Value:  
>
> Could not parse the remainder: '().order_by('-votes')' from 
> 'poll.altword_set.all().order_by('-votes')'
>
>
>
> How do I write the correct syntax for ordering my list?
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to