-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to expand writable related fields on POST #24
Comments
Hi Ben - I see, thanks for this. I can think of a couple work arounds for your situation, (e.g. recreate the serializer within the view), but I think a more involved fix isn't that trivial. Welcome any pull requests if you manage to look into it (you'd need to modify the serializers module) |
Hi @BerniWittmann - I realise this is over 2 years old, so apologies, and no worries if you've forgotten altogether, but I had a question. Am I right to assume that you wanted to post the ID only of the country, but to receive in the response, the fully serialized country? |
Hey @evenicoulddoit, no worries :) I have forgotten about it either. I guess that this was true indeed. |
I'm still struggling with this issue today. |
@nebiyuelias1 can you tell me more? |
I am basically trying to do the same exact thing as @BerniWittmann. |
Adding the extensions_expand field to a view somehow makes a field you wanted to expand required somehow. |
…PI response Change from using a library (see commit 78f8c42) for this to specifying the serializers by hand. The library was too buggy, particularly the following issue but also others: evenicoulddoit/django-rest-framework-serializer-extensions#24
I try to create an object via a POST request. This works very well, now to my problem:
I want the response to have the field expanded by default (in the direct response to the post request).
When trying this either via
http://localhost:8000/api/cities?expand=country
or settingextensions_expand = {'country'}
on the view (my preferred way), i get a validation error"country": ["This field is required." ]
.So using
extensions_expand={'country'}
results in an error on POST (and also PUT i think). I can bypass this error by usingget_extensions_mixin_context
on the viewThis works at least, but still doesn't produce the desired result of having
country
expanded in the post response.I also have a repo ready for reproduction: https://github.com/BerniWittmann/drf_serializer_ext
Just try to post something to
localhost:8000/api/cities
. The desired response would be:If anything is unclear, let me know :)
The text was updated successfully, but these errors were encountered: