title: Django Multiple Files Upload Using Ajax without forms
body: <p>I have an aplication in Django 2.0 where one user can upload many images of their diplomas at the same time but also, I need to make this with ajax so the page will not reload.</p>
  
  <p>This is my <strong>models.py</strong></p>
  
  <pre><code>class diploma(models.Model):
      user = models.ForeignKey(user, on_delete=models.CASCADE, null=True)
      diploma=models.ImageField(default='nopic.png', null=True)
      def __str__(self):
          return self.diploma
  </code></pre>
  
  <p>And this is my file input in my template <strong>upload.html</strong></p>
  
  <pre><code>&lt;script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"&gt;&lt;/script&gt;
  
  &lt;input type="file" id="images" name="images[]" multiple accept="image/jpg,image/png,image/jpeg,image/gif"&gt;
  &lt;a onclick="uploadWithAjax()"&gt; Upload Images &lt;/a&gt;
  </code></pre>
  
  <p>If you notice, there's no Form html tag. Just an 'a' link that calls the function uploadWithAjax().</p>
  
  <p>This is my script with the uploadWithAjax() function</p>
  
  <pre><code>function uploadWithAjax()
  {
    var files = $('#images')[0].files;
    $.ajax(
    {
      type: "POST",
      url: "/UploadImages/",
      data: "", //I DON'T KNOW WHAT DATA I HAVE TO PUT HERE
      success: function(result)
      {
        alert('IMAGES UPLOADED');
      }
    });
  }
  </code></pre>
  
  <p>I Think I have to send the 'files' variable in the 'data' atribute of ajax, but I'm not sure becouse there are files and dont normal inputs. Please help.</p>
  
  <p>This is my <strong>ajax.py</strong> file, where I recive the images</p>
  
  <pre><code>def UploadImages(request):
    diplomas = request.FILES['images'] #I don't know if this is correct
  </code></pre>
  
  <p>I didn't finish the view becouse I don't know how to continue or how to make a register in my bd table for each image I uploaded. Please Help!</p>