Search code examples
pythondjangotastypie

Updating a field on multiple Resources in tastypie


I have a tastypie ModelResource that I'd like to use to update one field of multiple instances of this Model at once.

class Message(models.Model):
    # ... fields etc
    unread = models.BooleanField(default=True)

I have tried to send a PATCH request (in tests, at the moment), but this doesn't work:

api = TestApiClient()
data = {'unread': False}
api.patch('/path/to/resource/', data=data)

Does anyone have any ideas? Thanks.


Solution

  • If you're using a patch request to update a field of several instances, you have to send objects. Like so :

    data = {objects:[{'unread':False,'resource_uri':'uri/of/your/instance'},{'unread':False,'resource_uri':'uri/of/your/instance'}]}
    

    More infos here and here