diff options
Diffstat (limited to 'app/photos/models.py')
-rw-r--r-- | app/photos/models.py | 76 |
1 files changed, 43 insertions, 33 deletions
diff --git a/app/photos/models.py b/app/photos/models.py index d3024d9..f0d5540 100644 --- a/app/photos/models.py +++ b/app/photos/models.py @@ -10,12 +10,14 @@ from django.conf import settings from taggit.managers import TaggableManager from locations.models import Location, Region + def get_upload_path(self, filename): - return "images/galleries/originals/%s/%s" % (datetime.datetime.today().strftime("%Y"), filename) + return "images/galleries/original/%s/%s" % (datetime.datetime.today().strftime("%Y"), filename) + class LuxImage(models.Model): image = models.FileField(blank=True, null=True, upload_to=get_upload_path) - title = models.CharField(null=True,blank=True, max_length=300) + title = models.CharField(null=True, blank=True, max_length=300) caption = models.TextField(blank=True, null=True) pub_date = models.DateTimeField() exif_raw = models.TextField(blank=True, null=True) @@ -33,8 +35,8 @@ class LuxImage(models.Model): location = models.ForeignKey(Location, null=True, blank=True) is_public = models.BooleanField(default=True) is_video = models.BooleanField(default=False) - flickr_id = models.CharField(null=True,blank=True, max_length=80) - + flickr_id = models.CharField(null=True, blank=True, max_length=80) + class Meta: ordering = ('-pub_date', 'id') verbose_name_plural = 'Images' @@ -43,12 +45,45 @@ class LuxImage(models.Model): def __str__(self): return "%s" % self.pk + def get_image_name(self): + return self.image.url.split("galleries/original/")[1] + + def get_image_size(self, size="original"): + base = self.get_image_name() + return "%sgalleries/%s/%s" % (settings.IMAGES_URL, size, base) + def admin_thumbnail(self): - return force_text('<a href="%s"><img src="%s"></a>' % - (self.image.url, self.image.url)) + return force_text('<a href="%s"><img src="%s"></a>' % (self.image.url, self.image.url)) admin_thumbnail.allow_tags = True admin_thumbnail.short_description = 'Thumbnail' + +class LuxGallery(models.Model): + title = models.CharField(blank=True, max_length=300) + description = models.TextField(blank=True, null=True) + slug = models.CharField(blank=True, max_length=300) + thumb = models.CharField(blank=True, max_length=300) + image = models.ManyToManyField(LuxImage) + pub_date = models.DateTimeField(null=True) + point = models.PointField(null=True, blank=True) + location = models.ForeignKey(Location, null=True, blank=True) + is_public = models.BooleanField(default=True) + + class Meta: + ordering = ('-pub_date', 'id') + verbose_name_plural = 'Galleries' + get_latest_by = 'pub_date' + + def __str__(self): + return self.title + + def get_main_image(self): + return "%sgallery_thumbs/%s.jpg" % (settings.IMAGES_URL, self.id) + + def get_absolute_url(self): + return "/photos/galleries/%s/" % (self.slug) + + class Photo(models.Model): description = models.TextField(blank=True, null=True) title = models.CharField(blank=True, max_length=300) @@ -84,8 +119,7 @@ class Photo(models.Model): ordering = ('-pub_date',) def admin_thumbnail(self): - return force_text('<a href="%s"><img src="%s"></a>' % - (self.get_absolute_url(), self.get_small_square_url())) + return force_text('<a href="%s"><img src="%s"></a>' % (self.get_absolute_url(), self.get_small_square_url())) admin_thumbnail.allow_tags = True admin_thumbnail.short_description = 'Thumbnail' @@ -120,7 +154,7 @@ class Photo(models.Model): return self.get_pic_url(size="medium") def get_original_url(self): - #return self.get_pic_url(size="original") + # return self.get_pic_url(size="original") return "http://farm%s.static.flickr.com/%s/%s_%s_o.jpg" % (self.flickr_farm, self.flickr_server, self.flickr_id, self.flickr_originalsecret) def get_retina_slideshow_url(self): @@ -209,30 +243,6 @@ class Photo(models.Model): def save(self, *args, **kwargs): super(Photo, self).save() -class Gallery(models.Model): - title = models.CharField(blank=True, max_length=300) - description = models.TextField(blank=True, null=True) - slug = models.CharField(blank=True, max_length=300) - thumb = models.CharField(blank=True, max_length=300) - image = models.ManyToManyField(LuxImage) - pub_date = models.DateTimeField(null=True) - point = models.PointField(null=True, blank=True) - location = models.ForeignKey(Location, null=True, blank=True) - - class Meta: - ordering = ('-pub_date', 'id') - verbose_name_plural = 'Galleries' - get_latest_by = 'pub_date' - - def __str__(self): - return self.title - - def get_main_image(self): - return "%sgallery_thumbs/%s.jpg" % (settings.IMAGES_URL, self.id) - - def get_absolute_url(self): - return "/photos/galleries/%s/" % (self.slug) - class PhotoGallery(models.Model): set_id = models.CharField(blank=True, max_length=300) |