How to display 2 featured and 8 organic products per page in Django based on rank and search query?

I’m working on a Django-based e-commerce application where products have fields like is_featured (boolean) and rank (integer). The goal is to create a paginated search results view where:

After searched each page displays 10 products in total. The first 2 products should always be featured (is_featured=True) and sorted by their rank. The remaining 8 products should be organic (is_featured=False) and also sorted by their rank. The products must match the search query (e.g., filtering by title or content).

Ensuring this logic works efficiently, especially with large datasets. Dynamically adjusting the number of organic products to fill the rest of the page if fewer than 2 featured products are available. I want to do with caching

Back to Top