8👍
The current user is stored in the request object, and you can’t get that in a model method unless you pass it in from elsewhere – which you can’t do in the upload_to function.
So you’ll need to approach this in a different manner – I would suggest doing it at the form level. You can pass the request object into the form’s __init__
method and store it in an instance attribute, where you can get to it in a custom upload handler. For documentation on upload handlers, look here.
5👍
If you added a user field to the model, and have that attribute set before you performed an upload, then you could get the user in to your upload_location function via the instance attribute.
- [Django]-Django: need help with keeping apps from depending on one another
- [Django]-Django URLResolver error
- [Django]-Collectstatic command excluding nested directories and files
4👍
First, don’t search the net for Django help. Search here only: http://docs.djangoproject.com/en/dev/
Second, the current user is part of Authentication.
http://docs.djangoproject.com/en/dev/topics/auth/#topics-auth
The user is recorded in the request. request.user