On 13 nov, 01:52, Tim <[EMAIL PROTECTED]> wrote:
> Just to add some more information - I have been messing around with
> making the upload_to a callable, but I still have the same problem in
> that I need to build the path based on information that only exists
> during runtime (that is, a call to a view). Basically, I don't know
> the value of upload_to until I'm in the view. Ideally I'd like to do
> the following actions in views.py:
>
> - import the model
> - set the upload_to value
> - save the file
>

Don't know if this can apply to your problem, but here's what we did:

# models.py

def get_upload_path(instance, filename):
    # store images under MEDIA_ROOT/myimages/<username>/filename
    return os.path.join("myimages", instance.owner.username, filename)

class Image(Model):
    """
    Media-Image
    """
    owner = models.ForeignKey(User)
    image_file = ImageField(
        upload_to=get_upload_path
        )
    # etc...


Then it's just a matter of passing the request.user to the model (or
to the form) within the view.

HTH




 What to do?
>
> - Tim
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to