Type error to create and update my list in django rest framework

后端 未结 3 1843
悲哀的现实
悲哀的现实 2021-01-17 01:57

I\'m trying to use my api to create and update products in a bundle. I did so:

model.py

class Business(models.Model):
    name = models.CharField(max         


        
3条回答
  •  爱一瞬间的悲伤
    2021-01-17 02:43

    The issue here is that you are posting a list to BundleProduct's product field yet it is an ForeignKey. To join Bundle to a Product, simply POST:

    {
      "bundle": 2,
      "product" 1,
      "number": 1
    }
    

    You can repeat this:

    {
      "bundle": 2,
      "product" 4,
      "number": 1
    }
    

    to add yet another product 4 to the same bundle and so on. Just make sure you do them one by one and not in a list as you had done earlier.

提交回复
热议问题