How do I upload files to a specific folder in Django?
<p>After the user uploads 2 .ini files, I would like it to save both files inside the following folder.</p>

<p>MEDIA/uploadedconfigs/Printer/Plastic/</p>

<p>However, it's currently saving to the address below.</p>

<p>MEDIA/uploadedconfigs/None/</p>

<p><br></p>

<p>Below is the code that uploads the files. <br>
models.py</p>

<pre><code>def UploadedConfigPath(instance, filename):

    return os.path.join('uploadedconfigs', str(instance.id), filename)

class ConfigFiles(models.Model):

    Printer = models.CharField(_('Printer Model'),
    max_length=100, blank=True, null=True, unique=False)
    Plastic = models.CharField(_('Plastic'),    
    max_length=40, blank=True, null=True, unique=False)
    creator = models.CharField(_('Creator'),
    max_length=40, blank=True, null=True, unique=False)
    HDConfig = models.FileField(_('High Detail'), 
    upload_to=UploadedConfigPath)
    LDConfig = models.FileField(_('Low Detail'), 
    upload_to=UploadedConfigPath)

    pub_date = models.DateTimeField(_('date_joined'), 
    default=timezone.now)
</code></pre>

<p>I'm not what "instance" is doing, but I was told it's what is spitting out the "None" folder name.  I was also told I may need to place the files in a temporary folder but I'm not sure what that would entail. Any help would be appreciated! </p>

<p>You could replace the function <code>UploadedConfigPath</code> with this :</p>

<pre><code>def UploadedConfigPath(instance, filename):
    return os.path.join('uploadedconfigs', 'Printer', 'Plastic', filename)
</code></pre>

<p><strong>Edit :</strong></p>

<p>This should do it :</p>

<pre><code>def UploadedConfigPath(instance, filename):
    return os.path.join('uploadedconfigs', instance.Printer, instance.Plastic, filename)
</code></pre>

python django