Skip to content
This repository has been archived by the owner on May 10, 2023. It is now read-only.

Allow multiple input formats? #25

Open
philippeluickx opened this issue Oct 24, 2015 · 11 comments
Open

Allow multiple input formats? #25

philippeluickx opened this issue Oct 24, 2015 · 11 comments

Comments

@philippeluickx
Copy link

My use case is simply to send a comma seperated list to the backend. So basically a string in my json payload.

{
...
tags: "first, second, third",
...
}

@glemmaPaul
Copy link
Owner

Hmmm that is more a renderer thing, Maybe we could make a parser option, like this:

field = TagListSerializerField(parser=CommaSeperatedTagsParser())

What do you think @philippeluickx ?

@philippeluickx
Copy link
Author

Sounds like a good idea to me to seperate it with parsers. That will allow to extend with customized parsers if needed.

@glemmaPaul
Copy link
Owner

Okay sounds good @philippeluickx, let's make this an enhancement for the next version.

@glemmaPaul glemmaPaul mentioned this issue Nov 2, 2015
6 tasks
@philippeluickx
Copy link
Author

You're a hero!

@jameskane05
Copy link

Using Django and Django Rest Framework connected to an Angular app, I'm trying to add tags to every WorkSample model I create. I create the models by submitting POST data to API endpoints. In this case, the model and form include a user-submitted image file, so I have to convert the POST data to a FormData object before POSTing so that DRF can interpret the image file (making sure to include parser_classes = ( FormParser, MultiPartParser,) in the model serializer to interpret a multi-part form).

That was working great before I added the tags field, using django-taggit and django-taggit-serializer. But trying to submit tag values through the FormData object results in this error: "{tags: ["Invalid json list. A tag list submitted in string form must be valid json."]}"

Is my issue related to this one, or am I just doing something wrong?

@vaibhav-jain
Copy link

@jameskane05 Did you found solution to this issue. I am getting this issue too.

@jameskane05
Copy link

I believe I did but I forget my solution... Let me get back to you tonight.

On Wed, Feb 17, 2016 at 1:00 AM, vaibhav jain notifications@github.com
wrote:

@jameskane05 https://github.com/jameskane05 Did you found solution to
this issue. I am getting this issue too.


Reply to this email directly or view it on GitHub
#25 (comment)
.

@vaibhav-jain
Copy link

@jameskane05 I get it working by submitting in this format ["tag1", "tag2"] .

@prokaktus
Copy link
Contributor

@glemmaPaul

field = TagListSerializerField(parser=CommaSeperatedTagsParser())

maybe it will be better to provide custom callable? Not object instance, but callable. And then, in to_internal_value, we can call:

if self.parser:
    data = self.parser(data)

I can implement this, if you like my idea ☕

@glemmaPaul
Copy link
Owner

@prokaktus Thank you very much for the offer and I'm definitely not saying no to that, just create a PR with the added changes.

I'm going to check out why the tests are failing this weekend (hopefully 📆 )!

@glemmaPaul glemmaPaul mentioned this issue May 27, 2016
4 tasks
@shazshah
Copy link

I came across this issue while google searching the problem when i encountered the same issue performing a POST. I eventually overcame the problem by changing the way i was making the POST.

Instead of (i am using HTTPie): http POST http://127.0.0.1:8000/api/v1/test/ test_text="Testing API with tags" tags=["test"]

(or whatever form generated the error for you) try:

http --json POST http://127.0.0.1:8000/api/v1/test/ test_text="Testing API with tags" tags='["test"]'

Hope this helps anyone else who encounters the issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants