python - How can I display range of objects using django pagination? -


i making ajax pagination template displaying 5x5 dota 2 player item backpack grid (see screenshot -- 1 made steam).

dota 2 player backpack

the thing is, page can have empty slots.

the following code not handle it. if second slot empty (no item having slot_nb field value 2), item object slot_nb of value 25 displayed on first page when should displayed on second 1 (slot_nb index starts @ 0)

def get_pagination_page(page=1):     items = items.objects.all()     paginator = paginator(items, 25) # 25 items per page     try:         page = int(page)     except valueerror:         page = 1      try:         items = paginator.page(page)     except (emptypage, invalidpage):         items = paginator.page(paginator.num_pages)      return items 

what want each page render item.objects.filter(slot_nb=range(((page_nb*25)-25)), ((page_nb*25)-1)) (page_nb starts @ 1)

is possible achieve this?

paginator perform slicing operation.

# paginator.py ... return page(self.object_list[bottom:top], number, self) 

so have make items ordering slot_nb

items = items.objects.all().order_by('slot_nb') 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

node.js - Bad Request - node js ajax post -

uitableview - Create and use custom prototype table cells in xamarin ios using storyboard -