-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Multiple fields with the same source clobber each other #4634
Labels
Milestone
Comments
Passing a list of ids to a PrimaryKeyRelatedField? Can you post what you are trying to achieve here? |
Hey @aswinm, basically I want to be able to:
FYI, the following code works and accomplishes 1 and 2, but not 3. class UserSerializer(serializers.ModelSerializer):
dog_objects = DogSerializer(source='dogs', many=True, read_only=True)
dog_ids = serializers.PrimaryKeyRelatedField(source='dogs', many=True, queryset=Dog.objects.all())
class Meta:
fields = ('dog_objects', 'dog_ids',)
model = User |
Having same exact problem. |
Awesome, thanks so much! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey guys, I'm getting weird behavior with many related fields. Is this an error?
Checklist
master
branch of Django REST framework.Steps to reproduce
Create a model serializer where one field renders the relation, and the other field writes to it.
Then do a patch.
Expected behavior
It should update my model.
Actual behavior
It throws an error complaining that nested writes aren't allowed.
tl;dr
This assertion gets called, but it checks all fields rather than just the writable ones:
https://github.com/tomchristie/django-rest-framework/blob/master/rest_framework/serializers.py#L721
The text was updated successfully, but these errors were encountered: