How to give the folder name using model instance in django
Question: New to python . Anyway I am on my way to first project.

See i need to upload multiple file into single folder so i come up with an
idea like this.

    
    
    folder_name1
    ------myfiles1.jpg
    ------myfiled2.jpg
    folder_name2
    ------mynewfiles.jpg
    ------mynewfiles1.jpg
    

And i read lot of tutorials this is my models.py

    
    
    def content_file_name(instance, filename):  
        return "uploads/{folder}/{file}".format(id=instance, folder=instance.albumname, file=filename)
    
    class Album(models.Model):
        albumname = models.CharField(max_length=100)
        audiofile = models.FileField(upload_to=content_file_name)#documents/%Y/%m/%d
    

Updated: This is my view.py

    
    
    def viewalbum(request):
        if request.method == 'POST':
            form = AlbumForm(request.POST, request.FILES)
            if form.is_valid():
                alubmnew = Album()
                albumvalue = Album()
    
                albumnew = Album(albumname = request.POST.get('albumname', None))
                albumvalue = Album(audiofile = request.FILES['audiofile'])
    
                #for albumvalue in request.FILES.getlist('audiofile'):
                albumvalue.save()
                albumnew.save()
                return HttpResponseRedirect(reverse('google.views.viewalbum'))
        else:
            form = AlbumForm()
        return render_to_response('audio/test.html',{'form': form}, context_instance=RequestContext(request))
    

The problem i am having right now is.. It doesn`t create albumname folder

And also in my form i can`t able to upload multiple file in single time. Its
actually takes only one file to upload...


Answer: 
    import os
    def content_file_name(instance, filename):   
        upload_dir = os.path.join('uploads', instance.albumname)  
        if not os.path.exists(upload_dir):
            os.makedirs(upload_dir)
        return os.path.join(upload_dir, filename)
    

