Изменить условия сортировки в пагинаторе


    <figure class="article-image is-4by3 padding">
                    {% thumbnail post_first.image "400x300" crop="left" as im %}
                      <img src="{{ im.url }}">
                    {% endthumbnail %}
                  </figure>
                <div class="article-body padding active">
                  <a href="{% url 'content:news_post' %}">
                    <h2 class="article-title padding">
                      {{post_first.title}}
                    </h2>
                  </a>
                  <p class="article-content padding">
                    {% autoescape on %}
                      {{ post_first.text|truncatewords:50}}
                    {% endautoescape %}
                  </p>
                  <footer class="article-info">
                    <span>{{ post_first.author }}</span>
                    <span>{{ post_first.pub_date|date:"d E Y" }}</span>
                  </footer>
                </div>
              <!--/a-->
              </div>
              <div class="columns padding">
              <div class="column nested-column article padding active">
              <!--a href="{% url 'content:news_post' %}"-->
                <figure class="article-image is-16by9 padding">
                  {% thumbnail post_second.image "500x300" crop="left" as im %}
                    <img src="{{ im.url }}">
                  {% endthumbnail %}
                </figure>
                <div class="article-body padding active">
                  <a href="{% url 'content:news_post' %}">
                    <h2 class="article-title padding">
                      {{post_second.title}}
                    </h2>
                  </a>
                  <p class="article-content padding">
                    {% autoescape on %}
                      {{ post_second.text|truncatewords:75}}
                    {% endautoescape %}
                  </p>
                  <footer class="article-info">
                    <span>{{ post_second.author }}</span>
                    <span>{{ post_second.pub_date|date:"d E Y" }}</span>
                  </footer>
                </div>
              <!--/a-->
              </div>
                <div class="column padding">
                  <a class="article" href="{% url 'content:news_post' %}">
                    <figure class="article-image is-16by9 padding">
                      {% thumbnail post_threeth.image "240x135" as im %}
                        <img src="{{ im.url }}" alt="">
                      {% endthumbnail %}
                    </figure>
                    <div class="article-body padding">
                      <h2 class="article-title padding">
                        {{post_threeth.title}}
                      </h2>
                      <p class="article-content padding">
                        {% autoescape on %}
                          {{ post_threeth.text|truncatewords:10}}
                        {% endautoescape %}
                      </p>
                      <footer class="article-info">
                        <span>{{ post_threeth.author }}</span>
                        <span>{{ post_threeth.pub_date|date:"d E Y" }}</span>
                      </footer>
                    </div>
                  </a>
                  {% for post in posts %}
                  <a class="article" href="#">
                    <div class="article-body padding">
                      <h2 class="article-title padding">
                        {{post.title}}
                      </h2>
                      <p class="article-content padding">
                        {{post.text|truncatewords:10}}
                      </p>
                      <footer class="article-info">
                        <span>{{post.author}}</span>
                        <span>{{post.pub_date|date:"d E Y"}}</span>
                      </footer>
                    </div>
                  </a>
                  {% endfor %}
                </div>
              </div>
            </section>
            <section class="column">
              <a class="article active" href="{% url 'content:news_post' %}">
                <figure class="article-image is-3by2 padding">
                  {% thumbnail post_fourth.image "240x160" as im %}
                    <img src="{{ im.url }}" alt="">
                  {% endthumbnail %}
                </figure>
                <div class="article-body padding">
                  <h2 class="article-title padding">
                    {{post_fourth.title}}
                  </h2>
                  <p class="article-content padding">
                    {% autoescape on %}
                      {{ post_fourth.text|truncatewords:15}}
                    {% endautoescape %}
                  </p>
                  <footer class="article-info">
                    <span>{{ post_fourth.author }}</span>
                    <span>{{ post_fourth.pub_date|date:"d E Y" }}</span>
                  </footer>
                </div>
              </a>
              {% for post1 in posts1 %}
              <a class="article active" href="#">
                <div class="article-body padding">
                  <h2 class="article-title padding">
                    {{ post1.title }}
                  </h2>
                  <p class="article-content padding">
                    {% autoescape on %}
                      {{ post1.text|truncatewords:10}}
                    {% endautoescape %}
                  </p>
                  <footer class="article-info">
                    <span>{{post1.author}}</span>
                    <span>{{post1.pub_date|date:"d E Y"}}</span>
                  </footer>
                </div>
              </a>
              {% endfor %}
            </section>
          </div>
        </div>
        {% include 'includes/paginator.html' %}

У меня страница новостей, на ней выводится 6 блоков со статьями (по убыванию).

Первый блок - это вывод последней опубликованной статьи

Второй блок - это вывод 2-й статьи

Третий блок - это вывод 3-й статьи

Четвёртый блок - это вывод 4-й статьи

Пятый блок - это вывод с 4-й по 6-ю статью

Шестой блок - это вывод с 6-й по 9-ю статью, и к нему подключена пагинация.

Если я нажимаю "перейти на следующую страницу", то на ней отображается все что было на первой странице. Мне нужно, чтобы начиная со второй страницы, статьи выводились в таком порядке:

Первый блок - каждая 10-я статья

Второй блок - каждая 11-я статья

Третий блок - каждая 12-я статья

Четвёртый блок - каждая 13-я статья

Пятый блок - каждая 14-16-я начиная с 14-ой

Шестой блок - каждая 17-19-я начиная с 17-ой. То-есть, нужно чтобы на первой странице он выводил один набор сортировки в context, а со второй странице он выводил второй набор сортировки в context.

Подскажите, можно ли как то реализовать такую пагинацию? Вот мой код views функции:

def news(request):
    posts = Post.objects.order_by('-pub_date')[4:6]
    posts1 = Post.objects.order_by('-pub_date')[6:9]
    post_first = Post.objects.order_by('-pub_date')[0]
    post_second = Post.objects.order_by('-pub_date')[1]
    post_threeth = Post.objects.order_by('-pub_date')[2]
    post_fourth = Post.objects.order_by('-pub_date')[3]
    post_first1 = Post.objects.order_by('-pub_date')[10::11]
    post_second1 = Post.objects.order_by('-pub_date')[11::12]
    post_threeth1 = Post.objects.order_by('-pub_date')[12::13]
    post_fourth1 = Post.objects.order_by('-pub_date')[13::14]
    posts2 = Post.objects.order_by('-pub_date')[13::14:16]
    posts11 = Post.objects.order_by('-pub_date')[16::17:19]
    paginator = Paginator(post1, 3)
    page_number = request.GET.get('page')
    page_obj = paginator.get_page(page_number)
    if page_number ==1:
        context= {
            'page_obj':page_obj,
            'posts':posts,
            'posts1':posts1,
            'post_first':post_first,
            'post_second':post_second,
            'post_threeth':post_threeth,
            'post_fourth':post_fourth,
        }
    else:
        context= {
            'page_obj':page_obj,
            'posts':posts2,
            'posts1':posts11,
            'post_first':post_first1,
            'post_second':post_second1,
            'post_threeth':post_threeth1,
            'post_fourth':post_fourth1,
        }
    

    return render(request, 'content/news.html', context)

Ответы (0 шт):