set upload path for speaker pictures

This commit is contained in:
Thomas Steen Rasmussen 2017-02-18 12:44:12 +01:00
parent c6b27de400
commit cb5c2386eb
2 changed files with 34 additions and 2 deletions

View file

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-02-18 11:43
from __future__ import unicode_literals
from django.db import migrations, models
import program.models
class Migration(migrations.Migration):
dependencies = [
('program', '0022_auto_20170218_1148'),
]
operations = [
migrations.AlterField(
model_name='speaker',
name='picture_large',
field=models.ImageField(blank=True, null=True, upload_to=program.models.get_speaker_picture_upload_path),
),
migrations.AlterField(
model_name='speaker',
name='picture_small',
field=models.ImageField(blank=True, null=True, upload_to=program.models.get_speaker_picture_upload_path),
),
]

View file

@ -102,12 +102,17 @@ class EventInstance(CreatedUpdatedModel):
return minutes / settings.SCHEDULE_TIMESLOT_LENGTH_MINUTES return minutes / settings.SCHEDULE_TIMESLOT_LENGTH_MINUTES
def get_speaker_picture_upload_path(instance, filename):
""" We want speaker pictures are saved as MEDIA_ROOT/speakers/bornhack-2016/filename """
return 'speakers/%s/%s' % (instance.camp.slug, filename)
class Speaker(CreatedUpdatedModel): class Speaker(CreatedUpdatedModel):
""" A Person anchoring an event. """ """ A Person anchoring an event. """
name = models.CharField(max_length=150) name = models.CharField(max_length=150)
biography = models.TextField() biography = models.TextField()
picture_small = models.ImageField(null=True, blank=True) picture_small = models.ImageField(null=True, blank=True, upload_to=get_speaker_picture_upload_path)
picture_large = models.ImageField(null=True, blank=True) picture_large = models.ImageField(null=True, blank=True, upload_to=get_speaker_picture_upload_path)
slug = models.SlugField(blank=True, max_length=255) slug = models.SlugField(blank=True, max_length=255)
camp = models.ForeignKey('camps.Camp', null=True, related_name="speakers") camp = models.ForeignKey('camps.Camp', null=True, related_name="speakers")
events = models.ManyToManyField( events = models.ManyToManyField(
@ -127,3 +132,4 @@ class Speaker(CreatedUpdatedModel):
self.slug = slugify(self.name) self.slug = slugify(self.name)
super(Speaker, self).save(**kwargs) super(Speaker, self).save(**kwargs)