That is because

Question.objects.order_by("-pub_date")


would give you a list of all records so you can simply apply slicing
without the use of . operator.
For understanding purpose, you can break down your code as

result = Question.objects.order_by("-pub_date")
> latest_question_list = result[:5]


This is a feature provided by *Python* itself.
Would suggest going through the Django docs about ORM in case you have not.

On Sat, Apr 13, 2019, 1:09 PM Mayur Bagul <[email protected]> wrote:

> Hello Judge95,
>
> thanks for useful information but i want to know how [:5] is used without
> . operator and how it is work.
>
> thanking you.
>
> On Friday, April 12, 2019 at 7:31:49 PM UTC+5:30, OnlineJudge95 wrote:
>>
>> The part you want to understand is same as ORDER BY clause in SQL. The
>> slicing will provide only the top 5 results. By default the order_by sorts
>> in ascending order only. But providing a "-" would make it to sort in
>> descending order.
>>
>> On Fri, Apr 12, 2019, 6:56 PM Mayur Bagul <[email protected]> wrote:
>>
>>> Hello coders,
>>>
>>> I'm here to understand line of code which im unable to understand how it
>>> work.
>>> i'm looking forward to get help from you.
>>>
>>> code is given below :
>>>
>>>
>>> from django.shortcuts import render
>>>
>>> from .models import Question
>>>
>>>
>>> def index(request):
>>>     latest_question_list = Question.objects.order_by*('-pub_date')[:5]*
>>>     context = {'latest_question_list': latest_question_list}
>>>     return render(request, 'polls/index.html', context)
>>>
>>>
>>>
>>>
>>> - in the code above i'm looking forward to know about bold and
>>> highlighted part how it work ?
>>>
>>> --
>>> 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 [email protected].
>>> To post to this group, send email to [email protected].
>>> 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/bbc7142c-bf46-4fb4-8e25-bbe7a2594c9f%40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-users/bbc7142c-bf46-4fb4-8e25-bbe7a2594c9f%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> On Fri, Apr 12, 2019, 6:56 PM Mayur Bagul <[email protected]> wrote:
>>
>>> Hello coders,
>>>
>>> I'm here to understand line of code which im unable to understand how it
>>> work.
>>> i'm looking forward to get help from you.
>>>
>>> code is given below :
>>>
>>>
>>> from django.shortcuts import render
>>>
>>> from .models import Question
>>>
>>>
>>> def index(request):
>>>     latest_question_list = Question.objects.order_by*('-pub_date')[:5]*
>>>     context = {'latest_question_list': latest_question_list}
>>>     return render(request, 'polls/index.html', context)
>>>
>>>
>>>
>>>
>>> - in the code above i'm looking forward to know about bold and
>>> highlighted part how it work ?
>>>
>>> --
>>> 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 [email protected].
>>> To post to this group, send email to [email protected].
>>> 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/bbc7142c-bf46-4fb4-8e25-bbe7a2594c9f%40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-users/bbc7142c-bf46-4fb4-8e25-bbe7a2594c9f%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> 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/4dd06d2a-1a88-4a9e-916a-28bf29fc97d5%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/4dd06d2a-1a88-4a9e-916a-28bf29fc97d5%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
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/CAD%3DM5eRjwV8W7-EfLHFPq-%3DjoJVdwOYb-03WZctrL56LFPY7RA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to