def move(self, move): if move == self.UP: mm = Page.objects.get(challenge=self.challenge, order=self.order - 1) mm.order += 1 mm.save() self.order -= 1 self.save() elif move == self.DOWN: mm = Page.objects.get(challenge=self.challenge, order=self.order + 1) mm.order -= 1 mm.save() self.order += 1 self.save() elif move == self.FIRST: pages = Page.objects.filter(challenge=self.challenge) idx = index(pages, self) pages[idx].order = pages[0].order - 1 pages = sorted(pages, key=lambda page: page.order) self.normalize_page_order(pages) elif move == self.LAST: pages = Page.objects.filter(challenge=self.challenge) idx = index(pages, self) pages[idx].order = pages[len(pages) - 1].order + 1 pages = sorted(pages, key=lambda page: page.order) self.normalize_page_order(pages)
def move(self, move): if move == self.UP: mm = Page.objects.get( challenge=self.challenge, order=self.order - 1 ) mm.order += 1 mm.save() self.order -= 1 self.save() elif move == self.DOWN: mm = Page.objects.get( challenge=self.challenge, order=self.order + 1 ) mm.order -= 1 mm.save() self.order += 1 self.save() elif move == self.FIRST: pages = Page.objects.filter(challenge=self.challenge) idx = index(pages, self) pages[idx].order = pages[0].order - 1 pages = sorted(pages, key=lambda page: page.order) self.normalize_page_order(pages) elif move == self.LAST: pages = Page.objects.filter(challenge=self.challenge) idx = index(pages, self) pages[idx].order = pages[len(pages) - 1].order + 1 pages = sorted(pages, key=lambda page: page.order) self.normalize_page_order(pages)