title: How to assign Foreign key inside loop Django
body: <p>I want to assign a foreign key to each color in a loop</p>
  <pre class="lang-py prettyprint-override"><code>colorArray=[{color:'red', product_id:5}, {color:'yellow', product_id:5}]
  </code></pre>
  <p>Product Model</p>
  <pre class="lang-py prettyprint-override"><code>class Product(models.Model):
      name = models.CharField(max_length=500)
      brand = models.CharField(max_length=500)
      description = models.CharField(max_length=500)
  </code></pre>
  <p>Color Model</p>
  <pre class="lang-py prettyprint-override"><code>class Color(models.Model):
      colorName = models.CharField(max_length=500)
      product_id = models.ForeignKey(Product, on_delete=models.CASCADE)
  </code></pre>
  <p>Views</p>
  <pre class="lang-py prettyprint-override"><code>class AddColors(APIView):
      def post(self,request):
          for i in colorArray:
              s=AddColors()
              s.colorName=i['color']
              s.product_id=i[Product.objects.get(id=i['product_id'])]
              s.save()
          return Response({'colors Saved'})
  </code></pre>
  <p><img src="https://i.stack.imgur.com/tWdFS.png" alt="" /></p>