models.py 1.09 KB
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.template.defaultfilters import truncatewords
3
from representatives.models import Representative
Arnaud Fabre's avatar
Arnaud Fabre committed
4

Nicolas Joyard's avatar
Nicolas Joyard committed
5

6
7
8
9
10
11
12
13
14
KIND_CHOICES = (
    ('other', 'Other'),
    ('blog', 'Blog post'),
    ('social', 'Social network'),
    ('press', 'Press interview'),
    ('parliament', 'Parliament debate'),
)


Arnaud Fabre's avatar
Arnaud Fabre committed
15
class Position(models.Model):
16
    representative = models.ForeignKey(Representative,
17
                                       related_name='positions')
Arnaud Fabre's avatar
Arnaud Fabre committed
18
    datetime = models.DateField()
19
20
21
    kind = models.CharField(max_length=64, choices=KIND_CHOICES,
                            default='other')
    title = models.CharField(max_length=500, null=True)
Arnaud Fabre's avatar
Arnaud Fabre committed
22
    text = models.TextField()
Nicolas Joyard's avatar
Nicolas Joyard committed
23
    link = models.URLField(max_length=500)
24
    score = models.IntegerField(default=0)
Arnaud Fabre's avatar
Arnaud Fabre committed
25
26
    published = models.BooleanField(default=False)

27
28
29
30
    @property
    def short_title(self):
        return truncatewords(self.title, 5)

Arnaud Fabre's avatar
Arnaud Fabre committed
31
32
33
34
35
36
37
38
39
    @property
    def short_text(self):
        return truncatewords(self.text, 5)

    def publish(self):
        self.published = True

    def unpublish(self):
        self.published = False