title: django save file into folder
body: <p>I want to save the file into separate folder but the folder name i will get it from the form that i dont know . but i have the working form now that will saved into user_ (something).</p>
  
  <p>Can anybody tell me how to define the model class and views to get the folder name and the file which i upload saved automatically into the separate folder.  </p>
  
  <p>models.py</p>
  
  <pre><code>def content_file_name(instance, filename):
      return "user_{id}/{file}".format(id=instance, file=filename)
  
  class Audio(models.Model):
      audiofile = models.FileField(upload_to=content_file_name)
  </code></pre>
  
  <p>views.py</p>
  
  <pre><code>def saved_file(request):
      # Handle file upload
      if request.method == 'POST':
          form = AudioForm(request.POST, request.FILES)
          if form.is_valid():
              newaudio = AudioForm()
              newaudio = Audio(audiofile = request.FILES['audiofile'])
              newaudio.save()
  
              #This is for redirect to the file save_list after post 
              return HttpResponseRedirect(reverse('app.views.saved_file'))
      else:
          form = AudioForm()
  
      # Load documents for the save_list page
      showfiles = Audio.objects.all()
      return render_to_response(
          'audio/file_upload.html',
          {'showfiles': showfiles, 'form': form},
          context_instance=RequestContext(request)
      )
  </code></pre>