summaryrefslogtreecommitdiff
path: root/app/resume/models.py
blob: aec1a2e59d8cb7ce74a94fe3e98d4ceac931e0fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from django.db import models
from django.core.urlresolvers import reverse

# http://freewisdom.org/projects/python-markdown/
import markdown


class Publisher(models.Model):
    name = models.CharField(max_length=200)
    slug = models.SlugField(max_length=50)
    body_markdown = models.TextField(null=True, blank=True)
    body_html = models.TextField(null=True, blank=True)
    url = models.CharField(max_length=200, blank=True, null=True)
    payment_time = models.DecimalField(max_digits=2, decimal_places=0)

    def __str__(self):
        return self.name


class PubItem(models.Model):
    title = models.CharField(max_length=200)
    slug = models.CharField(max_length=50)
    body_markdown = models.TextField(null=True, blank=True)
    body_html = models.TextField(null=True, blank=True)
    url = models.CharField(max_length=200, blank=True, null=True)
    pub_date = models.DateTimeField('Date published')
    publisher = models.ForeignKey(Publisher)

    class Meta:
        ordering = ('-pub_date',)

    def __str__(self):
        return self.title

    def get_absolute_url(self):
        return reverse("resume:detail", kwargs={"publisher": self.publisher.slug, "slug": self.slug})

    def save(self, *args, **kwargs):
        if self.body_markdown:
            self.body_html = markdown.markdown(self.body_markdown, extensions=['extra'], safe_mode=False)
        super(PubItem, self).save()