MySQL データベースから取得したユーザーに応じて、動的に割り当てられたディレクトリにファイルをアップロードしようとしています。ドキュメントによると、このuploads_to
関数は 2 つの引数しか受け付けないため、別の変数を挿入して返されたパス文字列を完成させることはできないと思いますか? 以下のコード スニペット:
models.py
def item_uploads_to(instance, filename, userName):
return '/home/' + userName would go here + '/path/to/uploads/' + filename
class Document2(models.Model):
docfile2 = models.FileField(upload_to=item_uploads_to)
ビュー.py
userName = 'python' # this is a test value, working DB query code goes here
item_uploads_to(instance, filename, userName)