Show links on cards, cycle alphabetically
[copyspeak.git] / src / words / models.py
1 from django.core.urlresolvers import reverse
2 from django.db import models
3 from django.utils.translation import ugettext_lazy as _
4
5
6 ALIGNMENTS = (
7     (u'lawful', u'Lawful'),
8     (u'neutral', u'Neutral'),
9     (u'chaotic', u'Chaotic'),
10 )
11
12
13 class Word(models.Model):
14     word = models.CharField(_('word'), max_length=255, db_index=True)
15     slug = models.SlugField(_('slug'), unique=True)
16     alignment = models.CharField(_('alignment'), max_length=64, choices=ALIGNMENTS)
17     examples = models.TextField(_('examples'))
18     usage = models.TextField(_('usage'))
19     recommendations = models.TextField(_('recommendations'))
20
21     class Meta:
22         verbose_name = _('word')
23         verbose_name_plural = _('words')
24         ordering = ('word',)
25
26     def __unicode__(self):
27         return self.word
28
29     def get_absolute_url(self):
30         return reverse('words_word', args=[self.slug])
31
32     def get_next(self):
33         try:
34             return Word.objects.filter(word__gt=self.word)[0]
35         except IndexError:
36             return Word.objects.all()[0]
37
38     def get_previous(self):
39         words = Word.objects.order_by('-word')
40         try:
41             return words.filter(word__lt=self.word)[0]
42         except IndexError:
43             return words[0]