title: how can users upload file into Django model?
body: <p>With these codes, I want each user to be able to upload their own file in their own model</p>
  <p>forms.py:</p>
  <pre><code>class sp_UserNewOrderForm(forms.Form):
      file= forms.FileField()
  </code></pre>
  <p>models.py:</p>
  <pre><code>class sp_Order(models.Model):
      owner = models.ForeignKey(User, on_delete=models.CASCADE)
  
      def __str__(self):
          return self.owner.username
  
  
  class sp_OrderDetail(models.Model):
      order = models.ForeignKey(sp_Order, on_delete=models.CASCADE)
      file= models.FileField()
  
      def __str__(self):
          return self.order.owner.username
  </code></pre>
  <p>views.py:</p>
  <pre><code>@login_required
  def add_user_order(request):
      new_order_form = sp_UserNewOrderForm(request.POST or None)
  
      if new_order_form.is_valid():
          order = sp_Order.objects.filter(owner_id=request.user.id).first()
          if order is None:
              order = sp_Order.objects.create(owner_id=request.user.id)
  
          file= new_order_form.cleaned_data.get('file')
          order.sp_orderdetail_set.create(file=file)
          # todo: redirect user to user panel
          # return redirect('/user/orders')
  
          return redirect('/')
  
      return redirect('/')
  </code></pre>
  <p>HTML:</p>
  <pre><code>&lt;form method=&quot;post&quot; action=&quot;/add_sp&quot;&gt;
       {% csrf_token %}
       {{ form.count }}
       &lt;button type=&quot;submit&quot; class=&quot;btn btn-primary container&quot;&gt;
            upload
       &lt;/button&gt;
   &lt;/form&gt;
  </code></pre>
  <p>But these codes do not create the model. what is the problem?</p>