0

I have a django model like this, (BTW: I am using Tastypie)

class Watchlist(models.Model):
  name = models.CharField(max_length=200)
  created = models.DateTimeField(auto_now_add=True)
  user = models.ForeignKey('users.User')
  stocks = models.ManyToManyField('Stock')
  equityboss = models.BooleanField(blank=True, default=False)
  last_watched =  models.DateTimeField(auto_now_add=True)
  order = models.IntegerField(max_length=10)

I want to update order field alone for all the objects in watchlist model.

I tried by sending PUT request, it erased all my records. I didn't get any error. This is the data I send via PUT request

{'objects': [{'resource_uri': '/api/eboss/watchlist/2/', 'id': u'2', 'order': 0}, {'resource_uri': '/api/eboss/watchlist/1/', 'id': u'1', 'order': 1}]}

Please tell me what is the problem?

4

1 回答 1

2

查看 HTTP PATCH(RFC)- Tastypie(他们的文档)支持它,并允许您部分更新资源。

但是,您似乎需要为每个资源制作单独的 PATCH,因为没有提及 PATCH 列表的方式与您可以 PUT 列表的新副本相同。

于 2013-07-19T12:10:19.923 回答