title: How to insert data in for foreign key attribute from django views?
body: <p>This is my model with two foreign key attribute:</p>
  
  <pre><code>
  class Count(models.Model):
      userId = models.ForeignKey(User, on_delete=models.CASCADE)
      channelId = models.ForeignKey(News_Channel, on_delete=models.CASCADE)
      rate = models.PositiveIntegerField(default=0)
  
      def __str__(self):
          return self.channelId.name
  
      class Meta:
          ordering = ["-id"]
  
  </code></pre>
  
  <p>I want to insert some data when user in login , so i write following code in my views.py file</p>
  
  <pre><code>    for i in range(1,10):
          obj = Count.objects.filter(userId=request.user.id, channelId=cid)
          if not obj:
              o = Count.objects.create(id=Count.objects.all().count() + 1,userId=request.user.id, channelId=i,rate=0)
              o.save()
          i += 1
  
  </code></pre>
  
  <p>I have channel id from 1 to 10 in my db but I am getting following error:</p>
  
  <pre><code>ValueError: Cannot assign "1": "Count.channelId" must be a "News_Channel" instance.
  
  </code></pre>
  
  <p>Kindly help to insert data.</p>