title: Django save rows of html table selected by checkbox in the database
body: <p>I have a table in my models which the stocks are saving in it and its name is Stocks </p>
  
  <p>this table is desplayed in a template and i want to put a checkbox beside each row to save the checked row in another table of the model</p>
  
  <p>here ismy model.py :</p>
  
  <pre><code>class Stocks(models.Model):
     user=models.ForeignKey(User, null=True)
     name=models.CharField(max_length=128,verbose_name=_('stockname'))
     number=models.CharField(blank=True,null=True,max_length=64,verbose_name=_('number'))
  
     brand=models.CharField(max_length=64, validators=[
      RegexValidator(regex='^[A-Z]*$',message=_(u'brand must be in Capital letter'),)]
      ,verbose_name=_('brand'))
      comment=models.CharField(blank=True,null=True,max_length=264,verbose_name=_('comment'))
      price=models.PositiveIntegerField(blank=True,null=True,verbose_name=_('price'))
      date=models.DateTimeField(auto_now_add = True,verbose_name=_('date'))
      confirm=models.CharField(choices=checking,max_length=12,verbose_name=_('confirmation'), default=_('pending'))
      def __str__(self):
        return str(self.id)
      class Meta:
        verbose_name=_('Stock')
        verbose_name_plural=_('Stocks')
      def get_absolute_url(self):
        return reverse('BallbearingSite:mystocks' )
  
  
  class SellerDesktop(models.Model):
    seller=models.OneToOneField(User, related_name='seller', blank=True, null=True)
    buyer=models.OneToOneField(User, related_name='buyer', blank=True, null=True)
    stock=models.ForeignKey(Stocks, related_name='stocktoseller', blank=True, null=True)
    def __str__(self):
       return str(self.seller) + '-' + str(self.buyer)
    class Meta:
       verbose_name=_('SellerDesktop')
       verbose_name_plural=_('SellerDesktop')
  </code></pre>
  
  <p>and the Template :</p>
  
  <pre><code>&lt;form method="post"&gt;
   {% csrf_token %}
  &lt;table  id="example" class="table table-list-search table-responsive table-hover table-striped" width="100%"&gt;
  
  
           {% for item in myst %}
  
               &lt;td&gt;&lt;input type="checkbox" name="sendtoseller" value="{{ item.id }}"&gt;&lt;/td&gt;
               &lt;td&gt;{{ item.user.profile.companyname}}&lt;/td&gt;
               &lt;td&gt;{{ item.name }}&lt;/td&gt;
               &lt;td&gt;{{ item.brand }}&lt;/td&gt;
               &lt;td&gt;{{ item.number }}&lt;/td&gt;
               &lt;td&gt;{{ item.pasvand }}&lt;/td&gt;
               &lt;td&gt;{{ item.comment }}&lt;/td&gt;
               &lt;td&gt;{{ item.price }}&lt;/td&gt;
               &lt;td&gt;{{ item.date|timesince }}&lt;/td&gt;
  
           &lt;/tr&gt;
  
           {% endfor %}
  
  
    &lt;/table&gt;
  
         &lt;div style="text-align: center;  margin-top:0.5cm; margin-bottom:1cm;"&gt;
           &lt;input type="submit" name="toseller" value="Submit to seller "  style="color:red; width:100%;"/&gt;
         &lt;/div&gt;
        &lt;/form&gt;
  </code></pre>
  
  <p>and the view :</p>
  
  <pre><code> def allstocks_view(request):
     if request.method=='POST':
        tosave = request.POST.getlist('sendtoseller')
        stockid=Stocks.objects.filter(id=tosave) 
        SellerDesktop.objects.create(buyer=request.user,stock=stockid)
  
     stocks_list=Stocks.objects.all().filter(confirm=_('approved') ).order_by('-date')
  
        #paginating for table
     page = request.GET.get('page', 1)
     paginator = Paginator(stocks_list, 15)
     try:
       myst = paginator.page(page)
     except PageNotAnInteger:
       myst = paginator.page(1)
     except EmptyPage:
       myst = paginator.page(paginator.num_pages)
  
     context={
          'allstocks':stocks_list,
          'myst':myst,
      }
     return render(request,'BallbearingSite/sellerstocks.html',context)
  </code></pre>
  
  <p>this error was showed up</p>
  
  <p>TypeError at /sellerstocks/</p>
  
  <p>int() argument must be a string, a bytes-like object or a number, not 'list'</p>
  
  <p>when i changed the code to :</p>
  
  <pre><code>         stockid=Stocks.objects.filter(id=tosave[0])
  </code></pre>
  
  <p>this error was showed up:</p>
  
  <p>ValueError at /sellerstocks/</p>
  
  <p>Cannot assign "[]": "SellerDesktop.stock" must be a "Stocks" instance.</p>
  
  <p>How can i insert the selected rows into new table?</p>