models.py 827 Bytes
Newer Older
Arnaud Fabre's avatar
Arnaud Fabre committed
1
from django.db import models
Jamesie Pic's avatar
Jamesie Pic committed
2
from django.core.urlresolvers import reverse
Jamesie Pic's avatar
Jamesie Pic committed
3
from django.template.defaultfilters import truncatewords
4
from representatives.models import Representative
Arnaud Fabre's avatar
Arnaud Fabre committed
5

Nicolas Joyard's avatar
Nicolas Joyard committed
6

Arnaud Fabre's avatar
Arnaud Fabre committed
7
class Position(models.Model):
8
    representative = models.ForeignKey(Representative,
9
                                       related_name='positions')
Arnaud Fabre's avatar
Arnaud Fabre committed
10
11
    datetime = models.DateField()
    text = models.TextField()
Nicolas Joyard's avatar
Nicolas Joyard committed
12
    link = models.URLField(max_length=500)
Arnaud Fabre's avatar
Arnaud Fabre committed
13
14
15
16
17
18
19
20
21
22
23
    published = models.BooleanField(default=False)

    @property
    def short_text(self):
        return truncatewords(self.text, 5)

    def publish(self):
        self.published = True

    def unpublish(self):
        self.published = False
Jamesie Pic's avatar
Jamesie Pic committed
24
25

    def get_absolute_url(self):
Jamesie Pic's avatar
Jamesie Pic committed
26
        return reverse('representatives_positions:position-detail',
27
                       args=(self.pk,))