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 <mayur.bag...@gmail.com> 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 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/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 <mayur.bag...@gmail.com> 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 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/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 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/CAD%3DM5eTqF%2B-AKXxG5QADXsouGPCsRNWfsM1tLahFiL7DzGKtUQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to