When a user uploads images on to the website they are uploaded to a location specified in MEDIA_ROOT. In my case it is a temporary folder (temp) MEDIA_ROOT = '/opt/myenv/temp'
. I would like to have these images transferred from /opt/myenv/temp
to /opt/myenv/permanent
once the user confirms his identity by signing in.
Below are the steps that I am following, I am stuck in Step 2, can some one please guide me:
1.Appending the Django session id to the image name before storing it in '/opt/myenv/temp'
views.py
def store_data(request):
thumbnail = request.FILES['myfile']
file_name = thumbnail.name
thumbnail.name = file_name + '_' + request.session.session_key
u = user_info.objects.create(thumbnail=thumbnail)
models.py
class user_info(models.Model):
thumbnail = models.FileField(upload_to=get_upload_file_name)
objects = models.Manager()
def __unicode__(self):
return self.f_name
def get_upload_file_name(instance,filename):
return "temp/%s" % (filename)
2.After the user signs in, I would like to move the images that have the same session id in its name to a new folder 'opt/myenv/permanent'
while replacing session_id in the image name with user_name