summaryrefslogtreecommitdiff
path: root/app/projects/models/natparks.py
blob: 608c5c355118b82b5a5bc1401a447a50ddca10ae (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
55
56
import datetime
from PIL import Image
from django.contrib.gis.db import models
from django.conf import settings
from jrnl.models import Entry
from photos.models import PhotoGallery
from locations.models import State


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


class NationalParks(models.Model):
    type = models.CharField(max_length=50)
    name = models.CharField(max_length=254)
    state = models.ForeignKey(State, null=True)
    size = models.CharField(max_length=10, null=True)
    fee = models.CharField(max_length=5, null=True)
    camping_fee = models.CharField(max_length=10, null=True)
    url = models.CharField(max_length=250, null=True)
    code = models.CharField(max_length=16)
    unit_name = models.CharField(max_length=254)
    date_visited_begin = models.DateField('Date Visited', null=True)
    date_visited_end = models.DateField('Date Visited', null=True)
    date_park_created = models.DateField('Date Park Created', null=True)
    zoom = models.IntegerField(null=True)
    mpoly = models.MultiPolygonField(null=True)
    visited = models.BooleanField(default=False)
    dek = models.TextField(null=True, blank=True)
    tag_line = models.CharField(max_length=254, null=True)
    post = models.ForeignKey(Entry, null=True)
    gallery = models.ForeignKey(PhotoGallery, blank=True, null=True, verbose_name='photo set')
    image = models.FileField(upload_to=get_upload_path, null=True, blank=True,
                             help_text="width: 980px, height: > 450px")
    image_height = models.CharField(max_length=20, null=True, blank=True)
    image_width = models.CharField(max_length=20, null=True, blank=True)
    objects = models.GeoManager()

    class Meta:
        verbose_name_plural = "National Parks"
        app_label = 'projects'
        ordering = ('-visited', 'unit_name',)

    def __str__(self):
        return self.unit_name

    @property
    def get_image_url(self):
        return "%s%s" % (settings.IMAGES_URL, self.image.name[7:])

    def save(self):
        #get image dimensions
        img = Image.open(self.image)
        self.image_width, self.image_height = img.size
        super(NationalParks, self).save()