X-Git-Url: https://git.mdrn.pl/copyspeak.git/blobdiff_plain/2374306a346a48eb02bcedf0ce19694a1b0b7c25..a5fbac2f74911db5050559e577ce8613ac6514e9:/src/words/models.py diff --git a/src/words/models.py b/src/words/models.py index 095382b..cc1b1c1 100644 --- a/src/words/models.py +++ b/src/words/models.py @@ -28,3 +28,16 @@ class Word(models.Model): def get_absolute_url(self): return reverse('words_word', args=[self.slug]) + + def get_next(self): + try: + return Word.objects.filter(word__gt=self.word)[0] + except IndexError: + return Word.objects.all()[0] + + def get_previous(self): + words = Word.objects.order_by('-word') + try: + return words.filter(word__lt=self.word)[0] + except IndexError: + return words[0]