-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
In browsable API unselecting the checkbox for a boolean field doesn't update the field, but using raw data does update the field #8762
Comments
Just FYI, GitHub allows you to upload images 😅 |
Here is the model: `
`` here's the serializer: `class CurrencySerializer(serializers.Serializer):
here're the views: `class CurrencyListCreateAPIView(generics.ListCreateAPIView):
|
Sorry, I don't know how to post the code so it is correctly shown. |
Hi, is that issue already solved? If not - can I work on it? |
It is not solved for me 🙂 |
you can work on it. |
this code is not right, ListCreateAPIView only support get and post, not support put |
Please, use the class CurrencySerializer(serializers.ModelSerializer):
id = serializers.IntegerField(read_only=True)
company = serializers.PrimaryKeyRelatedField(read_only=True)
name = serializers.ChoiceField(choices=settings.CURRENCY_CHOICES)
owner = serializers.StringRelatedField()
class Meta:
model = Currency
fields = ["id", "company", "name", "owner"] You can spli the serializer and use different serializer in ModelViewSet with def_get_serializer_class base on Like: # views.py
from rest_framework import viewsets
class MyModelViewSet(viewsets.ModelViewSet):
# other
def get_serializer_class(self):
if self.action == "create":
# return create serializer class
elif self.action in ["update", "partial_update"]:
# return the serualizer class made for the PATCH/PUT
# made last one for the list/retieve action
#serializers.py
class CurrencyUpdateSerializer(serializers.ModelSerializer):
name = serializers.ChoiceField(choices=settings.CURRENCY_CHOICES)
owner = serializers.StringRelatedField()
class Meta:
model = Currency
fields = ["name", "owner"]
class CurrencyRetrieveListSerializer(serializers.ModelSerializer):
class Meta:
fields = "__all__" You have more control for action of drf and the HTTP method |
I'm facing this same issue as well. Do you guys know when it could be fixed? |
I noticed that when I unselect the boolean field that was already True to set it to False via browsable API – the field doesn't update.
Here's an example:
https://capture.dropbox.com/k3xcrwjBS9aK4fVT
After unselecting "invoiced" and clicking PUT, the data stays the same (I edited the price value too):
https://capture.dropbox.com/bT46reH9ushS8nge
But when I edit the RAW data text field:
https://capture.dropbox.com/pDYjaAHHsvNqE79K
The value gets updated:
https://capture.dropbox.com/mC9UwhQBLrt1yEOE
It works on all of my endpoints the same way. I wonder if this is a bug or if I am doing something wrong.
The text was updated successfully, but these errors were encountered: