Hi, so my infinite pagination only works when i am using regular views, but i think there is a problem with class based views as only the first 6 Items are shown and i cannot scroll down for infinite pagination.
I am using a search form to search for the items (but it returns only 6 and i cannot scroll further and clicking on MORE also gives me error.
class SearchResultsView(ListView):
model = retailer
paginate_by = 6
context_object_name = "prods"
template_name = 'testing/search_results.html'
ordering = ['price']
def get_queryset(self):
query = self.request.GET.get('q')
if query :
All = retailer.objects.filter(title__icontains=query)
return All
else:
pass
MY HTML TEMPLATE:
{% block content %}
<div class="flexbox-container infinite-container">
{% for item in prods %}
<div class="flexbox-item infinite-item">
<a href="/{{item.slug}}"><img src="{{item.image.url}}"></a>
<div class="Main-Info">
<div class = "Shop"><b>{{item.shop}}</b></div>
<div class = "Title">{{item.title | truncatechars:29}}</div>
<a href="/{{item.slug}}" target="_blank"><div class = "Price">
{% if item.price == 0 %}
<b>"Click Here To Find Price" </b></div> </a>
{% elif item.country == "USA" %}
<b>${{item.price}}</b></div></a>
{% else %}
<b>£{{item.price}}</b></div> </a>
{% endif %}
</div>
</div>
{% endfor %}
</div>
{% if page_obj.has_next %}
<a class="infinite-more-link" href="?page={{ page_obj.next_page_number }}">More</a>
{% endif %}
<div class="loader"></div>
</div>
{% endblock content %}
Clicking on More gives me error
TypeError at /search/
object of type 'NoneType' has no len()
SO then i removed the pagination but then all the 100 plus items load
Please Help, Thanks