Pipeline update.
[copyspeak.git] / src / words / models.py
index 095382b..cc1b1c1 100644 (file)
@@ -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]