title: How to save image to user folder in django?
body: <p>I'd like to save uploaded images to separate folders. So for example user 4 photos should be stored in /media/images/4/</p>
  
  <p>Here is the function and model and views that I came up with:</p>
  
  <p>Model:</p>
  
  <pre><code>def get_uplaod_file_name(user,filename):
      return 'photos/%s/%s_%s' %  str(user.id),  (str(time()).replace('.','_'), filename)
  
  
  
  class UserPic(models.Model):
      user = models.ForeignKey(User, unique=False)
      picfile = ImageWithThumbsField(upload_to= get_uplaod_file_name, sizes=((200,200),(1200,1200)))
      caption = models.CharField(max_length=200 , blank=True, null=True)
      created_at = models.DateTimeField(auto_now_add=True)
  
  
      @models.permalink
      def get_absolute_url(self):
          return ('view_pirate', None, {'user': self.account.user})    
  
      def __unicode__(self):
          return unicode(self.picfile.name) 
  </code></pre>
  
  <p>Views:</p>
  
  <pre><code>@login_required
  def upload(request):
      # Handle file upload
      thisuser =User.objects.get(username = request.user.username)
      # Load pics of this user
  
      if request.method == 'POST':
          picform = PicForm(request.POST, request.FILES)
          if picform.is_valid():
              newpic = UserPic(picfile = request.FILES['picfile'])
              newpic = picform.save(commit=False)
              newpic.user_id = request.user.id
              newpic.save()
              message = "file %s is uploaded" % newpic
  
      else:
          picform = PicForm() # A empty, unbound form
  
      args= {}
      args['picform'] = picform
  
      return render_to_response('userpics/upload.html',args,
          context_instance=RequestContext(request))        
  </code></pre>
  
  <p>However, after many tweaks of <code>get_uplaod_file_name</code> it still does not work. I get errors like:</p>
  
  <pre><code>TypeError at /pics/upload/
  not enough arguments for format string
  </code></pre>
  
  <p>Appreciate your help to resolve this. </p>