Changed the upload_to of item pictures to a static functions, as lambdas

do not work in migrations
This commit is contained in:
Raphael Michel
2015-07-26 16:25:31 +02:00
parent e47cbdd6e5
commit 984730b31b
2 changed files with 31 additions and 4 deletions

View File

@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
import pretix.base.models
class Migration(migrations.Migration):
dependencies = [
('pretixbase', '0005_item_picture'),
]
operations = [
migrations.AlterField(
model_name='item',
name='picture',
field=models.ImageField(upload_to=pretix.base.models.itempicture_upload_to, null=True, verbose_name='Product picture', blank=True),
),
]

View File

@@ -774,6 +774,13 @@ class Question(Versionable):
self.event.get_cache().clear()
def itempicture_upload_to(instance, filename):
return '%s/%s/item-%s.%s' % (
instance.event.organizer.slug, instance.event.slug, instance.identity,
filename.split('.')[-1]
)
class Item(Versionable):
"""
An item is a thing which can be sold. It belongs to an event and may or may not belong to a category.
@@ -801,8 +808,11 @@ class Item(Versionable):
:param questions: A set of ``Question`` objects that should be applied to this item
:param admission: ``True``, if this item allows persons to enter the event (as opposed to e.g. merchandise)
:type admission: bool
:param picture: A product picture to be shown next to the product description.
:type picture: File
"""
event = VersionedForeignKey(
Event,
on_delete=models.PROTECT,
@@ -878,10 +888,7 @@ class Item(Versionable):
picture = models.ImageField(
verbose_name=_("Product picture"),
null=True, blank=True,
upload_to=lambda instance, filename: '%s/%s/item-%s.%s' % (
instance.event.organizer.slug, instance.event.slug, instance.identity,
filename.split('.')[-1]
)
upload_to=itempicture_upload_to
)
class Meta: