Answer the question
In order to leave comments, you need to log in
How to generate path to save file dynamically, DJANGO?
Here is the code
def upload_video(request):
v = Video(video = request.FILES['videoFile'])
v.safe()
class Video(models.Model):
video = model.FileField(upload_to="/path/")
Answer the question
In order to leave comments, you need to log in
At least there is this
https://docs.djangoproject.com/en/dev/ref/models/f...
username/time/
import os
import datetime
def user_directory_path(instance, filename):
# file will be uploaded to MEDIA_ROOT/user_<id>/<filename>
return os.path.join(
instance.user.name,
datetime.datetime.now().strftime('%Y_%m_%d__%H_%M'),
filename)
class MyModel(models.Model):
upload = models.FileField(upload_to=user_directory_path)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question