title: Django File Upload and Rename
body: <p>User is uploading a <em>.c</em> file of a particular question. I want the file to be renamed as 'userid_questionid.c'</p>
  
  <p>My models.py is :</p>
  
  <pre><code>from django.db import models
  
  class users(models.Model):
      username = models.CharField(max_length=20)
      password = models.CharField(max_length=20)
      score=models.IntegerField(max_length=3)
      def __unicode__(self):
          return self.username
  
  class questions(models.Model):
      question = models.TextField(max_length=2000)
      qid=models.IntegerField(max_length=2)
      def __unicode__(self):
         return self.qid
  
  def content_file_name(instance, filename):
      return '/'.join(['uploads', instance.questid.qid, filename])
  
  
  class submission(models.Model):
      user = models.ForeignKey(users)
      questid = models.ForeignKey(questions)
      file = models.FileField(upload_to=content_file_name)
  </code></pre>
  
  <p>I tried this. But it just creates the folder of user and saves file in it. Please help. Thank You. I need the file to be renamed.</p>