Whenever I do a model.destroy() with Backbone, it tries to do a DELETE request on the following URL:
http://localhost:8000/api/v1/item/?format=json
Since I am doing a destroy on a model, I would expect that the ID of the model should be passed, so the URL to do a DELETE request on would be this:
http://localhost:8000/api/v1/item/8/?format=json
where the ID is specified. Because of the lack of ID, and my use of tastypie, all items get deleted. How do I make it so that the URL contains the ID of the item that I wish to delete?
I’m guessing that your model looks something like this:
The
urlfor a model is supposed to be a function but, since it ends up going through the internalgetValuefunction, a string will also “work”; if you check the source I linked to, you’ll see why a string forurlwould give you the results you’re seeing.The solution is to use a function for
urlas you’re supposed to:You’d probably want something like this:
or this: