I have a model like this
def upload_location(instance, filename): return 'validate/%s/builds/%s' % (get_current_user(), filename) class MidletPair(models.Model): jad_file = models.FileField(upload_to = upload_location) jar_file = models.FileField(upload_to = upload_location) upload_to=tempfile.gettempdir()
How can I get the current user in upload_location () ...?
Side note: django's item search is confusing since there are a lot of things on the net up to 1.0.
The current user is stored in the request object, and you cannot receive it in the model method unless you transfer it from another location, which you cannot do in the upload_to function.
, - - . __init__ , . .
__init__
, upload_location .
-, Django. : http://docs.djangoproject.com/en/dev/
-, .
http://docs.djangoproject.com/en/dev/topics/auth/#topics-auth
. request.user
request.user
Source: https://habr.com/ru/post/1708263/More articles:https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1708258/clr-stored-procedures-alternatives-to-sqlcontextpipesendresultsstart-sendresultsrow-sendresultsend&usg=ALkJrhiVmcJ9hcyDbU9E33TmAPmy5CzlpwProcess shaping in Java - javaInteractive 3D surface object - wpfДоступ к текущей задаче для нумерации записей субрепортажа - ms-accessWhy does the Sharepoint Webservice add the # (pound) sign and identifier to the field values? - c #сортировать список объектов по свойству на связанном объекте - rubyIronPython and instances of COM objects - ironpythonMultiple rows colored differently in one JTable cell - javaSuggestions for introducing a very simple update that checks for a new version - language-agnosticCan a cucumber run my rspec-on-rails tests? - ruby | fooobar.comAll Articles