django-taggit-serializer
django-taggit-serializer copied to clipboard
Allow multiple input formats?
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", ... }
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 ?
Sounds like a good idea to me to seperate it with parsers. That will allow to extend with customized parsers if needed.
Okay sounds good @philippeluickx, let's make this an enhancement for the next version.
You're a hero!
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?
@jameskane05 Did you found solution to this issue. I am getting this issue too.
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 [email protected] 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 https://github.com/glemmaPaul/django-taggit-serializer/issues/25#issuecomment-185061384 .
@jameskane05 I get it working by submitting in this format ["tag1", "tag2"] .
@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 ☕
@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 📆 )!
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.