Exclude a type of post from pagination









up vote
0
down vote

favorite












I use a model for the posts of my blog that you can see here(Is a my old post).



As you can see, in that moldel, I've an option to indicate highlighted post. If I use the code below to implement the pagination on my blog, also the highlighted post is sent in a page different from the first.



 % for post in posts %
% if post.highlighted == 1 %
<h1><strong>Highlighted</strong></h1>
<a href=" post.get_absolute_url "><img src=" post.header_image " alt="Image of post.title "></a>
<h1><a href=" post.get_absolute_url "> post.title </a></h1>
<h4> post.tagline </h4>
% endif %
% endfor %
<hr><hr><hr>
% for post in posts %
% if post.highlighted == 0 %
<h1><strong>Not Highlighted</strong></h1>
<a href=" post.get_absolute_url "><img src=" post.header_image " alt="Image of post.title "></a>
<h1><a href=" post.get_absolute_url "> post.title </a></h1>
<p> post.tagline </p>
<h5> post.publishing_date</h5>
% for keyconcepts in post.keyconcepts.all %
<a href="#"># keyconcepts </a>&nbsp;
% endfor %
<hr>
% endif %

% endfor %

% block pagination %
% if is_paginated %
<div class="pagination px-auto">
<nav aria-label="Page navigation">
<ul class="pagination justify-content-center">
% if page_obj.has_previous %
<li class="page-item">
<a class="page-link text-center shadow" href=" request.path ?page= page_obj.previous_page_number ">Pagina precedente</a>
</li>
% endif %
<li class="page-item disabled">
<p class="page-link text-center shadow">Pagina page_obj.number di page_obj.paginator.num_pages .</p>
</li>
% if page_obj.has_next %
<li class="page-item">
<a class="page-link text-center shadow" href=" request.path ?page= page_obj.next_page_number ">Pagina successiva</a>
</li>
% endif %
</ul>
</nav>
</div>
% endif %
% endblock %


I would like to exclude all highlighted post from the pagination. Is it possible?



Below views.py



class ListPost(ListView):
model = Blog
context_object_name = 'posts'
queryset = Blog.objects.filter(category="G.I.S.") #FUNDAMENTAL FILTER
template_name = "blog/list_post.html"
paginate_by = 3









share|improve this question























  • But Willem gave you the answer to this in your original post, except you need to select is_highlighted=False.
    – Daniel Roseman
    Nov 11 at 21:51










  • I've adopted a different solution for the html template in relation to the my old post. I've updated the html code, sorry for my mistake.
    – Massimiliano Moraca
    Nov 11 at 21:59














up vote
0
down vote

favorite












I use a model for the posts of my blog that you can see here(Is a my old post).



As you can see, in that moldel, I've an option to indicate highlighted post. If I use the code below to implement the pagination on my blog, also the highlighted post is sent in a page different from the first.



 % for post in posts %
% if post.highlighted == 1 %
<h1><strong>Highlighted</strong></h1>
<a href=" post.get_absolute_url "><img src=" post.header_image " alt="Image of post.title "></a>
<h1><a href=" post.get_absolute_url "> post.title </a></h1>
<h4> post.tagline </h4>
% endif %
% endfor %
<hr><hr><hr>
% for post in posts %
% if post.highlighted == 0 %
<h1><strong>Not Highlighted</strong></h1>
<a href=" post.get_absolute_url "><img src=" post.header_image " alt="Image of post.title "></a>
<h1><a href=" post.get_absolute_url "> post.title </a></h1>
<p> post.tagline </p>
<h5> post.publishing_date</h5>
% for keyconcepts in post.keyconcepts.all %
<a href="#"># keyconcepts </a>&nbsp;
% endfor %
<hr>
% endif %

% endfor %

% block pagination %
% if is_paginated %
<div class="pagination px-auto">
<nav aria-label="Page navigation">
<ul class="pagination justify-content-center">
% if page_obj.has_previous %
<li class="page-item">
<a class="page-link text-center shadow" href=" request.path ?page= page_obj.previous_page_number ">Pagina precedente</a>
</li>
% endif %
<li class="page-item disabled">
<p class="page-link text-center shadow">Pagina page_obj.number di page_obj.paginator.num_pages .</p>
</li>
% if page_obj.has_next %
<li class="page-item">
<a class="page-link text-center shadow" href=" request.path ?page= page_obj.next_page_number ">Pagina successiva</a>
</li>
% endif %
</ul>
</nav>
</div>
% endif %
% endblock %


I would like to exclude all highlighted post from the pagination. Is it possible?



Below views.py



class ListPost(ListView):
model = Blog
context_object_name = 'posts'
queryset = Blog.objects.filter(category="G.I.S.") #FUNDAMENTAL FILTER
template_name = "blog/list_post.html"
paginate_by = 3









share|improve this question























  • But Willem gave you the answer to this in your original post, except you need to select is_highlighted=False.
    – Daniel Roseman
    Nov 11 at 21:51










  • I've adopted a different solution for the html template in relation to the my old post. I've updated the html code, sorry for my mistake.
    – Massimiliano Moraca
    Nov 11 at 21:59












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I use a model for the posts of my blog that you can see here(Is a my old post).



As you can see, in that moldel, I've an option to indicate highlighted post. If I use the code below to implement the pagination on my blog, also the highlighted post is sent in a page different from the first.



 % for post in posts %
% if post.highlighted == 1 %
<h1><strong>Highlighted</strong></h1>
<a href=" post.get_absolute_url "><img src=" post.header_image " alt="Image of post.title "></a>
<h1><a href=" post.get_absolute_url "> post.title </a></h1>
<h4> post.tagline </h4>
% endif %
% endfor %
<hr><hr><hr>
% for post in posts %
% if post.highlighted == 0 %
<h1><strong>Not Highlighted</strong></h1>
<a href=" post.get_absolute_url "><img src=" post.header_image " alt="Image of post.title "></a>
<h1><a href=" post.get_absolute_url "> post.title </a></h1>
<p> post.tagline </p>
<h5> post.publishing_date</h5>
% for keyconcepts in post.keyconcepts.all %
<a href="#"># keyconcepts </a>&nbsp;
% endfor %
<hr>
% endif %

% endfor %

% block pagination %
% if is_paginated %
<div class="pagination px-auto">
<nav aria-label="Page navigation">
<ul class="pagination justify-content-center">
% if page_obj.has_previous %
<li class="page-item">
<a class="page-link text-center shadow" href=" request.path ?page= page_obj.previous_page_number ">Pagina precedente</a>
</li>
% endif %
<li class="page-item disabled">
<p class="page-link text-center shadow">Pagina page_obj.number di page_obj.paginator.num_pages .</p>
</li>
% if page_obj.has_next %
<li class="page-item">
<a class="page-link text-center shadow" href=" request.path ?page= page_obj.next_page_number ">Pagina successiva</a>
</li>
% endif %
</ul>
</nav>
</div>
% endif %
% endblock %


I would like to exclude all highlighted post from the pagination. Is it possible?



Below views.py



class ListPost(ListView):
model = Blog
context_object_name = 'posts'
queryset = Blog.objects.filter(category="G.I.S.") #FUNDAMENTAL FILTER
template_name = "blog/list_post.html"
paginate_by = 3









share|improve this question















I use a model for the posts of my blog that you can see here(Is a my old post).



As you can see, in that moldel, I've an option to indicate highlighted post. If I use the code below to implement the pagination on my blog, also the highlighted post is sent in a page different from the first.



 % for post in posts %
% if post.highlighted == 1 %
<h1><strong>Highlighted</strong></h1>
<a href=" post.get_absolute_url "><img src=" post.header_image " alt="Image of post.title "></a>
<h1><a href=" post.get_absolute_url "> post.title </a></h1>
<h4> post.tagline </h4>
% endif %
% endfor %
<hr><hr><hr>
% for post in posts %
% if post.highlighted == 0 %
<h1><strong>Not Highlighted</strong></h1>
<a href=" post.get_absolute_url "><img src=" post.header_image " alt="Image of post.title "></a>
<h1><a href=" post.get_absolute_url "> post.title </a></h1>
<p> post.tagline </p>
<h5> post.publishing_date</h5>
% for keyconcepts in post.keyconcepts.all %
<a href="#"># keyconcepts </a>&nbsp;
% endfor %
<hr>
% endif %

% endfor %

% block pagination %
% if is_paginated %
<div class="pagination px-auto">
<nav aria-label="Page navigation">
<ul class="pagination justify-content-center">
% if page_obj.has_previous %
<li class="page-item">
<a class="page-link text-center shadow" href=" request.path ?page= page_obj.previous_page_number ">Pagina precedente</a>
</li>
% endif %
<li class="page-item disabled">
<p class="page-link text-center shadow">Pagina page_obj.number di page_obj.paginator.num_pages .</p>
</li>
% if page_obj.has_next %
<li class="page-item">
<a class="page-link text-center shadow" href=" request.path ?page= page_obj.next_page_number ">Pagina successiva</a>
</li>
% endif %
</ul>
</nav>
</div>
% endif %
% endblock %


I would like to exclude all highlighted post from the pagination. Is it possible?



Below views.py



class ListPost(ListView):
model = Blog
context_object_name = 'posts'
queryset = Blog.objects.filter(category="G.I.S.") #FUNDAMENTAL FILTER
template_name = "blog/list_post.html"
paginate_by = 3






django pagination django-templates django-views django-2.1






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 at 11:29

























asked Nov 11 at 21:46









Massimiliano Moraca

819




819











  • But Willem gave you the answer to this in your original post, except you need to select is_highlighted=False.
    – Daniel Roseman
    Nov 11 at 21:51










  • I've adopted a different solution for the html template in relation to the my old post. I've updated the html code, sorry for my mistake.
    – Massimiliano Moraca
    Nov 11 at 21:59
















  • But Willem gave you the answer to this in your original post, except you need to select is_highlighted=False.
    – Daniel Roseman
    Nov 11 at 21:51










  • I've adopted a different solution for the html template in relation to the my old post. I've updated the html code, sorry for my mistake.
    – Massimiliano Moraca
    Nov 11 at 21:59















But Willem gave you the answer to this in your original post, except you need to select is_highlighted=False.
– Daniel Roseman
Nov 11 at 21:51




But Willem gave you the answer to this in your original post, except you need to select is_highlighted=False.
– Daniel Roseman
Nov 11 at 21:51












I've adopted a different solution for the html template in relation to the my old post. I've updated the html code, sorry for my mistake.
– Massimiliano Moraca
Nov 11 at 21:59




I've adopted a different solution for the html template in relation to the my old post. I've updated the html code, sorry for my mistake.
– Massimiliano Moraca
Nov 11 at 21:59












1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










class ListPost(ListView):
queryset = Blog.objects.filter(is_highlighted=True)
context_object_name = 'posts'
template_name = "blog/list_post.html"
paginate_by = 3


Note Blog seems a misnomer. BlogPost seems more accurate.






share|improve this answer




















  • You suggestion is not correct. I don't want only the highlighted post, but all posts of "GIS" category and the pagination with the highlighted post, always, on the top of the list of the posts at the first page.
    – Massimiliano Moraca
    Nov 12 at 11:32






  • 1




    you did not mention anything about category until you edited it after I answered the question :|
    – rikAtee
    Nov 12 at 15:50











  • why not do queryset = Blog.objects.filter(category="G.I.S.", is_highlighted=True) ?
    – rikAtee
    Nov 12 at 15:52










  • Because I've this: django.core.exceptions.FieldError: Cannot resolve keyword 'is_highlighted' into field. Choices are: category, contents, draft, header_image, highlighted, id, keyconcepts, post_ptr, post_ptr_id, publishing_date, sl ug, tagline, timeaction_ptr, timeaction_ptr_id, title, updating_date
    – Massimiliano Moraca
    Nov 12 at 16:44











  • The answer is in the error - your field name is highlighted, not is_highlighted 🙃 so it's queryset = Blog.objects.filter(category="G.I.S.", highlighted=True)
    – rikAtee
    Nov 13 at 0:27











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53253571%2fexclude-a-type-of-post-from-pagination%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote



accepted










class ListPost(ListView):
queryset = Blog.objects.filter(is_highlighted=True)
context_object_name = 'posts'
template_name = "blog/list_post.html"
paginate_by = 3


Note Blog seems a misnomer. BlogPost seems more accurate.






share|improve this answer




















  • You suggestion is not correct. I don't want only the highlighted post, but all posts of "GIS" category and the pagination with the highlighted post, always, on the top of the list of the posts at the first page.
    – Massimiliano Moraca
    Nov 12 at 11:32






  • 1




    you did not mention anything about category until you edited it after I answered the question :|
    – rikAtee
    Nov 12 at 15:50











  • why not do queryset = Blog.objects.filter(category="G.I.S.", is_highlighted=True) ?
    – rikAtee
    Nov 12 at 15:52










  • Because I've this: django.core.exceptions.FieldError: Cannot resolve keyword 'is_highlighted' into field. Choices are: category, contents, draft, header_image, highlighted, id, keyconcepts, post_ptr, post_ptr_id, publishing_date, sl ug, tagline, timeaction_ptr, timeaction_ptr_id, title, updating_date
    – Massimiliano Moraca
    Nov 12 at 16:44











  • The answer is in the error - your field name is highlighted, not is_highlighted 🙃 so it's queryset = Blog.objects.filter(category="G.I.S.", highlighted=True)
    – rikAtee
    Nov 13 at 0:27















up vote
0
down vote



accepted










class ListPost(ListView):
queryset = Blog.objects.filter(is_highlighted=True)
context_object_name = 'posts'
template_name = "blog/list_post.html"
paginate_by = 3


Note Blog seems a misnomer. BlogPost seems more accurate.






share|improve this answer




















  • You suggestion is not correct. I don't want only the highlighted post, but all posts of "GIS" category and the pagination with the highlighted post, always, on the top of the list of the posts at the first page.
    – Massimiliano Moraca
    Nov 12 at 11:32






  • 1




    you did not mention anything about category until you edited it after I answered the question :|
    – rikAtee
    Nov 12 at 15:50











  • why not do queryset = Blog.objects.filter(category="G.I.S.", is_highlighted=True) ?
    – rikAtee
    Nov 12 at 15:52










  • Because I've this: django.core.exceptions.FieldError: Cannot resolve keyword 'is_highlighted' into field. Choices are: category, contents, draft, header_image, highlighted, id, keyconcepts, post_ptr, post_ptr_id, publishing_date, sl ug, tagline, timeaction_ptr, timeaction_ptr_id, title, updating_date
    – Massimiliano Moraca
    Nov 12 at 16:44











  • The answer is in the error - your field name is highlighted, not is_highlighted 🙃 so it's queryset = Blog.objects.filter(category="G.I.S.", highlighted=True)
    – rikAtee
    Nov 13 at 0:27













up vote
0
down vote



accepted







up vote
0
down vote



accepted






class ListPost(ListView):
queryset = Blog.objects.filter(is_highlighted=True)
context_object_name = 'posts'
template_name = "blog/list_post.html"
paginate_by = 3


Note Blog seems a misnomer. BlogPost seems more accurate.






share|improve this answer












class ListPost(ListView):
queryset = Blog.objects.filter(is_highlighted=True)
context_object_name = 'posts'
template_name = "blog/list_post.html"
paginate_by = 3


Note Blog seems a misnomer. BlogPost seems more accurate.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 12 at 0:58









rikAtee

4,75042956




4,75042956











  • You suggestion is not correct. I don't want only the highlighted post, but all posts of "GIS" category and the pagination with the highlighted post, always, on the top of the list of the posts at the first page.
    – Massimiliano Moraca
    Nov 12 at 11:32






  • 1




    you did not mention anything about category until you edited it after I answered the question :|
    – rikAtee
    Nov 12 at 15:50











  • why not do queryset = Blog.objects.filter(category="G.I.S.", is_highlighted=True) ?
    – rikAtee
    Nov 12 at 15:52










  • Because I've this: django.core.exceptions.FieldError: Cannot resolve keyword 'is_highlighted' into field. Choices are: category, contents, draft, header_image, highlighted, id, keyconcepts, post_ptr, post_ptr_id, publishing_date, sl ug, tagline, timeaction_ptr, timeaction_ptr_id, title, updating_date
    – Massimiliano Moraca
    Nov 12 at 16:44











  • The answer is in the error - your field name is highlighted, not is_highlighted 🙃 so it's queryset = Blog.objects.filter(category="G.I.S.", highlighted=True)
    – rikAtee
    Nov 13 at 0:27

















  • You suggestion is not correct. I don't want only the highlighted post, but all posts of "GIS" category and the pagination with the highlighted post, always, on the top of the list of the posts at the first page.
    – Massimiliano Moraca
    Nov 12 at 11:32






  • 1




    you did not mention anything about category until you edited it after I answered the question :|
    – rikAtee
    Nov 12 at 15:50











  • why not do queryset = Blog.objects.filter(category="G.I.S.", is_highlighted=True) ?
    – rikAtee
    Nov 12 at 15:52










  • Because I've this: django.core.exceptions.FieldError: Cannot resolve keyword 'is_highlighted' into field. Choices are: category, contents, draft, header_image, highlighted, id, keyconcepts, post_ptr, post_ptr_id, publishing_date, sl ug, tagline, timeaction_ptr, timeaction_ptr_id, title, updating_date
    – Massimiliano Moraca
    Nov 12 at 16:44











  • The answer is in the error - your field name is highlighted, not is_highlighted 🙃 so it's queryset = Blog.objects.filter(category="G.I.S.", highlighted=True)
    – rikAtee
    Nov 13 at 0:27
















You suggestion is not correct. I don't want only the highlighted post, but all posts of "GIS" category and the pagination with the highlighted post, always, on the top of the list of the posts at the first page.
– Massimiliano Moraca
Nov 12 at 11:32




You suggestion is not correct. I don't want only the highlighted post, but all posts of "GIS" category and the pagination with the highlighted post, always, on the top of the list of the posts at the first page.
– Massimiliano Moraca
Nov 12 at 11:32




1




1




you did not mention anything about category until you edited it after I answered the question :|
– rikAtee
Nov 12 at 15:50





you did not mention anything about category until you edited it after I answered the question :|
– rikAtee
Nov 12 at 15:50













why not do queryset = Blog.objects.filter(category="G.I.S.", is_highlighted=True) ?
– rikAtee
Nov 12 at 15:52




why not do queryset = Blog.objects.filter(category="G.I.S.", is_highlighted=True) ?
– rikAtee
Nov 12 at 15:52












Because I've this: django.core.exceptions.FieldError: Cannot resolve keyword 'is_highlighted' into field. Choices are: category, contents, draft, header_image, highlighted, id, keyconcepts, post_ptr, post_ptr_id, publishing_date, sl ug, tagline, timeaction_ptr, timeaction_ptr_id, title, updating_date
– Massimiliano Moraca
Nov 12 at 16:44





Because I've this: django.core.exceptions.FieldError: Cannot resolve keyword 'is_highlighted' into field. Choices are: category, contents, draft, header_image, highlighted, id, keyconcepts, post_ptr, post_ptr_id, publishing_date, sl ug, tagline, timeaction_ptr, timeaction_ptr_id, title, updating_date
– Massimiliano Moraca
Nov 12 at 16:44













The answer is in the error - your field name is highlighted, not is_highlighted 🙃 so it's queryset = Blog.objects.filter(category="G.I.S.", highlighted=True)
– rikAtee
Nov 13 at 0:27





The answer is in the error - your field name is highlighted, not is_highlighted 🙃 so it's queryset = Blog.objects.filter(category="G.I.S.", highlighted=True)
– rikAtee
Nov 13 at 0:27


















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53253571%2fexclude-a-type-of-post-from-pagination%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Top Tejano songwriter Luis Silva dead of heart attack at 64

政党

天津地下鉄3号線