24👍
UPDATE
is possible via 2 requests: PUT and PATCH
PUT
updates all the fields of the object on which the operation is to be performed. It basically iterates over all the fields and updates them one by one. Thus, if a required field is not found in the supplied data, it will raise an error.
PATCH
is what we call a Partial Update. You can update only the fields that are needed to be changed. Thus, in your case change your request method to PATCH
and your work will be done.
3👍
I was facing the same error after many experiments found something, so added all fields in serializer.py
in class meta, as shown below –
class Emp_UniSerializer( serializers.ModelSerializer ):
class Meta:
model = table
fields = '__all__' # To fetch For All Fields
extra_kwargs = {'std_code': {'required': False},'uni_code': {'required': False},'last_name': {'required': False},'first_name': {'required': False}}
Here, we can update any field, it won’t show error ["This field is required."]
- How to fix Error: pg_config executable not found on Elastic Beanstalk permanently
- Profiling Django webserver for high startup times
- Django – how can I access the form field from inside a custom widget
3👍
Add partial = True
argument in serializer as such:
serializer = BookSerializer(book, data=request.data, partial=True)
2👍
I’m not sure why it is sometimes that you look for hours for the answer, then ask, then immediately find the answer. I simply changed my request to be a ‘PATCH’ instead of a ‘PUT’.
- Django: AttributeError: 'NoneType' object has no attribute 'split'
- Django – annotate() – Sum() of a column with filter on another column
- Django – how to get user logged in (get_queryset in ListView)
- Filter Django Haystack results like QuerySet?