I would like to configure the mezzanine fork of django-filebrowser to create a subfolder when uploading an image, based on the title of a particular post within my mezzanine app.
The file field of that model requires setting "upload_to=", but I don't understand how I can make it point to a field value of its parent/foreignKey instance, rather than just a static value. I have tried defining a callable which points to exhibPost.title, as well as using it directly in the field as shown below.
I'd love to hear an explanation, I'm sure I'm misunderstanding something quite major about django here... Thanks
models.py - (imports omitted)
class exhibPost(Displayable, RichText,):
"""
An exhib post.
"""
def __unicode__(self):
return u'%s' % (self.id)
showstart = models.DateField("Show Starts")
showend = models.DateField("Show Ends")
start_time = models.TimeField(null=True, blank=True)
end_time = models.TimeField(null=True, blank=True)
summary = models.CharField(max_length=200,null=True,default=get_val)
class Meta:
verbose_name = _("exhib post")
verbose_name_plural = _("exhib posts")
ordering = ("-publish_date",)
class exhibImage(Orderable):
'''
An image for an exhib
'''
exhibPostKey = models.ForeignKey(exhibPost, related_name="images")
file = FileField(_("File"), max_length=200, format="Image",
upload_to=upload_to(
"theme.exhibImage.file",
----> exhibPost.title
)
)
class Meta:
verbose_name = _("Image")
verbose_name_plural = _("Images")
EDIT
@Anzel
The function I'm referring to is defined in my models as
def get_upload_path(instance, filename):
return os.path.join(
"user_%d" % instance.owner.id, "car_%s" % instance.slug, filename)
...and I call it in the same place that I arrowed originally.