I know how messed up this all seems, so I sympathize. I totally want
to store items according to a related object's name or id or whatever.
However, I'm using upload_to in a more straightforward manner, and it
seems to work out alright. Tell me if you've already tried it this
way:
class ScreenShot(models.Model):
def _image_location(instance, filename):
return ''.join("web_projects/%Y/", instance.project.slug,
"/", filename)
# ...
image = models.ImageField(upload_to=_image_location)
The thing you pass to your field's "upload_to" value can be a
callable, which takes two arguments: the instance of `ScreenShot`
being altered, and the filename of the original file that was
uploaded. You then just return a string of the path to save in,
including the filename.
It's all described here, which it looks like you've already read:
http://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.FileField.upload_to
Does that not work for you? I do exactly the same thing for various
fields on some of my models. I could see how it might complicate
things if you were doing it on an inline..... I admit that I haven't
tried that one out, as luck would have it. If the main model already
exists, it should work, though.
Just brainstorming to find a simpler solution. Have you already tried
it that way?
Tim