summaryrefslogtreecommitdiff
path: root/bak/unused_apps/people/models.py
blob: 1a07b169696e510d46b1e09e8d9b6080aa0e3d62 (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
42
43
44
45
46
47
48
49
50
51
52
53
54
from django.db import models
from django.template.defaultfilters import slugify

from taggit.managers import TaggableManager
from locations.models import Location
from utils.util import markdown_to_html


class Person(models.Model):
    first_name = models.CharField(max_length=200)
    last_name = models.CharField(max_length=200)
    email = models.EmailField(max_length=120, null=True, blank=True)
    street = models.CharField(max_length=355, null=True, blank=True)
    city = models.CharField(max_length=200, null=True, blank=True)
    state  = models.CharField(max_length=200, null=True, blank=True)
    postal_code = models.CharField(max_length=20, null=True, blank=True)
    country = models.CharField(max_length=200, null=True)
    phone = models.CharField(max_length=22, blank=True, null=True)
    slug = models.CharField(max_length=50, blank=True)
    body_markdown = models.TextField(null=True, blank=True)
    body_html = models.TextField(null=True, blank=True)
    tags = TaggableManager(blank=True)
    location_met = models.ForeignKey(Location, on_delete=models.CASCADE, null=True, blank=True)
    next_contact_date = models.DateField(null=True, blank=True)

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

    def __str__(self):
        return "%s %s" %(self.first_name, self.last_name)

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

    @property
    def get_previous_admin_url(self):
        n = self.get_previous_by_pub_date()
        return reverse('admin:%s_%s_change' %(self._meta.app_label,  self._meta.model_name),  args=[n.id] )

    @property
    def get_next_admin_url(self):
        model = apps.get_model(app_label=self._meta.app_label, model_name=self._meta.model_name)
        try:
            return reverse('admin:%s_%s_change' %(self._meta.app_label,  self._meta.model_name),  args=[self.get_next_by_pub_date().pk] )
        except model.DoesNotExist:
            return ''

    def save(self, *args, **kwargs):
        if not self.slug:
            self.slug = slugify(("%s-%s")[:50] %(self.last_name, self.first_name))
        if self.body_markdown:
            self.body_html = markdown_to_html(self.body_markdown)
        super(Person, self).save()