title: Django ModelForm Imagefield Upload
body: <p>I am pretty new to Django and I met a problem in handling image upload using ModelForm.
  My model is as following:</p>
  
  <pre><code>class Project(models.Model):
      name = models.CharField(max_length=100)
      description = models.CharField(max_length=2000)
      startDate = models.DateField(auto_now_add=True)
      photo = models.ImageField(upload_to="projectimg/", null=True, blank=True)
  </code></pre>
  
  <p>And the modelform is as following:</p>
  
  <pre><code>class AddProjectForm(ModelForm):
      class Meta:
          model = Project
          widgets = {
              'description': Textarea(attrs={'cols': 80, 'rows': 50}),
          }
          fields = ['name', 'description', 'photo']
  </code></pre>
  
  <p>And the View function is:</p>
  
  <pre><code>def addProject(request, template_name):
  if request.method == 'POST':
      addprojectform = AddProjectForm(request.POST,request.FILES)
      print addprojectform
      if addprojectform.is_valid():
          newproject = addprojectform.save(commit=False)
          print newproject
          print request.FILES
          newproject.photo = request.FILES['photo']
          newproject.save()
          print newproject.photo
  else:
      addprojectform = AddProjectForm()
  
  newProposalNum = projectProposal.objects.filter(solved=False).count()
  return render(request, template_name, {'addprojectform':addprojectform,
                                         'newProposalNum':newProposalNum})
  </code></pre>
  
  <p>the template is:</p>
  
  <pre><code>&lt;form class="bs-example form-horizontal" method="post" action=""&gt;{% csrf_token %}
                        &lt;h2&gt;Project Name&lt;/h2&gt;&lt;br&gt;
                        {{ addprojectform.name }}&lt;br&gt;
                        &lt;h2&gt;Project Description&lt;/h2&gt;
                        {{ addprojectform.description }}&lt;br&gt;
                        &lt;h2&gt;Image Upload&lt;/h2&gt;&lt;br&gt;
                        {{ addprojectform.photo }}&lt;br&gt;
                        &lt;input type="submit" class="btn btn-success" value="Add Project"&gt;
                    &lt;/form&gt;
  </code></pre>
  
  <p>Can anyone help me or could you give an example of image uploading?
  Thank you!</p>