I believe this is how the code is supposed to function. When you visit the 
index page the list should show the most recently posted/edited poll 
question.
For example:

Lets say we have 3 questions

   Question 1, published - 1 / 19 / 2017 - morning
  
   Question 2, published - 1 / 19 / 2017 - night

   Question 3, published - 1 / 20 / 2017 

When we call Question.objects.all() is passes the published date of each 
question model and lists them in ascending order. 
This means that the most recently edited or posted question will be on the 
bottom of the list and our list would like something like so:

   Question 3, Question, 2, Question 1

Now by adding '-' this tell django that we want to index our list in 
reverse order. Since everything is stored in ascending order as it is 
created, it is easy to look up things in descending order by reversing our 
list.
In this case the list isn't literally reversed merely indexed from the end 
of the list to the beginning.

So with that said if we call Question.objects.all('-pub_date') it will 
return to us our list in reverse order

Question 1, Question 2, Question 3. 
 ( The 5 within the brackets will return everything before the 5th index, 
index 0-4.)

Okay now with all that in mind I would recommend that you check out the 
polls admin page. On the Questions page i would delete all of the Questions 
that have already been created and i would recommend creating at least 6 
questions either manually 
or using a script to create a dummy database. Make sure that the pub date 
for each question is one day apart. 

Then in your polls.views under latest_question_list add 
    
   oldest_to_newest = Question.objects.all('pub_date')[:5]

 make sure to include oldest_to_newest in the context dictionary ( context 
{ 'item1': item1, 'item2': item2, }

With that complete edit index.html to look like so.
polls/templates/polls/index.html

{% if latest_question_list %}
    <ul>
    {% for question in latest_question_list %}
        <li><a href="/polls/{{ question.id }}/">{{ question.question_text 
}}</a></li>
    {% endfor %}
    </ul>
{% else %}
    <p>No polls are available.</p>
{% endif %}


<br />

{% if oldest_to_newest %}
    <ul>
    {% for question in oldest_to_newest %}
        <li><a href="/polls/{{ question.id }}/">{{ question.question_text }}
</a></li>
    {% endfor %}
    </ul>
{% else %}
    <p>No polls are available.</p>
{% endif %}


Now when you go to /polls you should see two lists the first in descending 
order and the second in ascending order and if you open your admin page in 
a new tab you can check the pub date of your Questions and compare that 
information to
what is being rendered so that you can more easily see what django is 
doing. 

Bottom line i believe there was a bit of a misunderstanding as to how the 
list would be rendered, between what you imagined it should look like and 
what the django tutorial explains will be rendered. Hopefully this will 
help you better understand whats going on
a bit better. I myself have gotten stuck on some parts of the tutorial and 
found that I've usually misread or misunderstood something in my haste or 
have created a bug while trying to type fast. 

Again hope this help, 
Victor

P.s. If the official tutorial leaves you with some questions and you need 
more information to feel confident while developing with django, I would 
recommend checking out tango with django and even django girls, they are 
both very indepth, and are focused on
building a website ready to publish from start to finish to help better 
understand the entire process of web-development and how django makes it 
easier to develop websites. Also spending time finding other django 
applications and learning how to use them with
your projects, for example bootstraps3, sekizai, and django-cms are a few 
applications you can install and include in your projects to help with the 
development process. 


On Thursday, January 19, 2017 at 2:21:32 PM UTC-5, DjangoUserDM wrote:
>
> I have a question about the "Polls" app, as described in the Django 
> Beginners' Tutorial, https://docs.djangoproject.com/en/1.10/intro/.  In 
> tutorial 3, the index view contains the following code:
>
>  
>
> latest_question_list = Question.objects.order_by('-pub_date')[:5]
>
>  
>
> It is stated that this produces the latest 5 questions according to 
> publication date.  The '-' in front of 'pub_date' is intended to return the 
> questions in descending rather than ascending order of publication date.  
> Yet when I tried this out, it returns the *earliest* 5 questions in my 
> database.  Is this an error, or (more likely), have I done something wrong?
>
> Thanks for any advice!
>
>  
>
> David
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/17e6978f-f06e-4105-862e-73b13055ef3c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to