summaryrefslogtreecommitdiff
path: root/app/projects/models/fiveby.py
blob: 473c095f4d749816d18ec2b90800b32d6b3e2737 (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
import datetime
from django.contrib.gis.db import models
from locations.models import Location, Region


def get_upload_path(self, filename):
    return "images/projects/videos/5x5/%s/%s" % (datetime.datetime.today().strftime("%Y"), filename)


def get_image_upload_path(self, filename):
    return "images/projects/5x5/%s/%s" % (datetime.datetime.today().strftime("%Y"), filename)


class FiveBy(models.Model):
    title = models.CharField(max_length=200)
    slug = models.SlugField(unique_for_date='pub_date')
    lede = models.TextField(blank=True)
    image = models.FileField(upload_to=get_image_upload_path, null=True, blank=True)
    videoh264 = models.FileField(upload_to=get_upload_path, null=True, blank=True)
    videoogg = models.FileField(upload_to=get_upload_path, null=True, blank=True)
    vimeo_link = models.CharField(max_length=200)
    youtube_link = models.CharField(max_length=200)
    pub_date = models.DateTimeField('Date published')
    PUB_STATUS = (
        (0, 'Draft'),
        (1, 'Published'),
    )
    status = models.IntegerField(choices=PUB_STATUS, default=0)
    point = models.PointField(null=True)
    location = models.ForeignKey(Location, on_delete=models.CASCADE, null=True)
    region = models.ForeignKey(Region, on_delete=models.CASCADE, null=True)

    class Meta:
        ordering = ('-pub_date',)
        get_latest_by = 'pub_date'
        app_label = 'projects'
        verbose_name_plural = '5x5'

    def __str__(self):
        return self.title

    def get_absolute_url(self):
        return "/%s/%s/%s/" % ('projects', '5x5', self.slug)

    @property
    def longitude(self):
        '''Get the site's longitude.'''
        return self.point.x

    @property
    def latitude(self):
        '''Get the site's latitude.'''
        return self.point.y