-
Notifications
You must be signed in to change notification settings - Fork 46
adding example usage (REST payloads) to the readme would be very helpful #16
Comments
I've ended up getting my requests working, but I still haven't figured out what the payload is supposed to look like to remove tags from a model. |
@honestbleeps Thanks for creating this issue. I've never thought about this. So are you saying that you also get no sufficient feedback when doing it wrong? |
Yeah, it may ultimately be a problem laying inside of Django Rest Framework and/or the tool I was using to test, Postman (a chrome extension). I was trying to send something like: key: tags and that didn't work, so then I figured I'd try: key: tags[] key: tags[] and that didn't work either... finally I realized you have to actually put array index numbers on Postman to send. There's no real way for I did maybe find a bug, though. I haven't been able to create a reduced test case, but once I got things working, I found that it wasn't overwriting the "tags" array, but rather adding any new tags that didn't exist to it and not removing them. It appears from your tests that if I patch MyModel with something like:
and it already has one tag, let's say "c", the end result should still be:
However, when I ran a PATCH request using Postman, with fields as follows:
I would end up with tags "a", "b" and "c" all on my model. I'm not sure why, and I am unable to stop what I'm working on at the moment to create a reduced test case. I will close this issue as I don't think it's one you can really respond to if django-rest-framework doesn't send you any actionable data (it empties out "tags" rather than passing on anything malformed). However, you might try updating your tests to do actual http requests rather than serializer.save calls to see if the bug I found is within your own code or maybe it's something odd I have in my own installation of django-rest-framework (but I wasn't doing a custom override of the PATCH method, so I wouldn't think my own code would be the issue) |
@honestbleeps Yes you are right, Forms don't go well with lists. When you would use JSON you could do the following: {
"tags": ["tag1", "tag2"]
} |
First and foremost: thanks for creating this, your work is appreciated!
I am unfortunately unable to get it working. I've got the GET request for my model returning
tags: []
as expected, but when I call a PATCH method and submit the data as either strings, a string representation of an array, etc, it doesn't seem to work.Because there isn't documentation on what my payload should look like, I've just tried everything I can think of, and it always comes back with an empty tag list, which makes it hard to know if I've configured something wrong or I'm sending the wrong payload. I've tried the following values for "tags" in my PATCH request:
foo
foo bar
["foo", "bar"]
["foo"]
so far, nothing gets created in the database, no error is thrown, etc, so it's unclear what I might be doing wrong.
I'd be happy to contribute back some examples if/when I get it working, but right now I'm a bit stymied!
The text was updated successfully, but these errors were encountered: