urbstudio/urbstudio/urb/models.py

90 lines
2.4 KiB
Python
Executable file

from django.db import models
from os.path import join
from sorl.thumbnail import get_thumbnail
def project_thumb_path(instance, filename):
return join('project_thumbs', instance.slug, filename)
class Project(models.Model):
title = models.CharField(max_length=255)
slug = models.SlugField()
thumb_image = models.ImageField(upload_to=project_thumb_path)
size_program = models.TextField(blank=True)
design_statement = models.TextField(blank=True)
extra_text = models.TextField(blank=True)
# start_date = models.DateField(blank=True)
# end_date = models.DateField(blank=True)
# location = models.CharField(max_length=255, blank=True)
class Meta:
ordering = ['-id']
def get_info(self):
return {
'id': self.id,
'title': self.title,
'slug': self.slug,
'thumb_image': self.thumb_image.url,
'size_program': self.size_program,
'design_statement': self.design_statement,
'extra_text': self.extra_text,
'images': self.get_images()
}
def get_images(self):
imgs = []
for i in self.projectimage_set.all():
image_url = get_thumbnail(i.image, "x450", crop="center").url
imgs.append({
'url': image_url,
'caption': i.caption
})
return imgs
def __unicode__(self):
return self.title
class ProjectImage(models.Model):
image = models.ImageField(upload_to='project_imgs/')
caption = models.CharField(max_length=255, blank=True)
project = models.ForeignKey(Project)
def __unicode__(self):
return self.caption
class SliderImage(models.Model):
image = models.ImageField(upload_to='slider_imgs/')
caption = models.CharField(max_length=255, blank=True)
order = models.IntegerField(default=1)
def __unicode__(self):
return self.caption
class Meta:
ordering = ['order']
class Link(models.Model):
title = models.CharField(max_length=255)
description = models.TextField(blank=True)
url = models.URLField(blank=True)
def __unicode__(self):
return self.title
class Noteworthy(models.Model):
image = models.ImageField(upload_to='noteworthy_imgs/')
title = models.CharField(max_length=255)
description = models.TextField(blank=True)
url = models.URLField(blank=True)
def __unicode__(self):
return self.title
# Create your models here.