Discussion:
How do we call bulk update for Model?
h***@gmail.com
2018-07-17 05:09:18 UTC
Permalink
I want to conduct bulk update for Model.
I know "PUT" action can be called by specific data. So we must set a new
action for the one.
This is my source code of bulk update.
https://github.com/encode/django-rest-framework/issues/6087
But, it couldn't work.
Because "validated_data" was empty even though I couldn't use the parameter
of read-only.
I think my source code is incorrect especially creating serializer for
ListSerializer.

Please let me know and give me your advice if you have a nice idea.
Thanks.
--
You received this message because you are subscribed to the Google Groups "Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-framework+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
hiroko matsumoto
2018-07-25 08:16:59 UTC
Permalink
This matter had been resolved by myself.
Thank you for showing my question!

```
class PostsViewSet(viewsets.ModelViewSet):
queryset = Posts.objects.all()
serializer_class = PostsSerializer
filter_class = PostsFilter
ordering_fields = ('created_at')

@action(methods=['patch'], detail=False)
def multi_update(self, request, *args, **kwargs):
queryset = self.filter_queryset(self.get_queryset())
serializer = self.get_serializer(instance=queryset,
data=request.data, many=True, partial=True) # add "partial=True"
valid = serializer.is_valid(raise_exception=True)
logger.error(serializer.validated_data)
self.perform_update(serializer)
return Response(serializer.data)
```
Post by h***@gmail.com
I want to conduct bulk update for Model.
I know "PUT" action can be called by specific data. So we must set a new
action for the one.
This is my source code of bulk update.
https://github.com/encode/django-rest-framework/issues/6087
But, it couldn't work.
Because "validated_data" was empty even though I couldn't use the
parameter of read-only.
I think my source code is incorrect especially creating serializer for
ListSerializer.
Please let me know and give me your advice if you have a nice idea.
Thanks.
--
You received this message because you are subscribed to the Google Groups
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-framework+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Rich Rauenzahn
2018-08-16 22:16:57 UTC
Permalink
Hi,

Is this still working for you on the latest version of DRF?

I'm trying to do the same, with almost an identical implementation (put
instead of patch), but DRF ends up calling exclude_current_instance() on
the queryset instead of a single object.

The same issue is documented here:
https://github.com/miki725/django-rest-framework-bulk/issues/68

That issue proposes copying to_internal_value() to a new class and
inserting a few lines of code.
Post by hiroko matsumoto
This matter had been resolved by myself.
Thank you for showing my question!
```
queryset = Posts.objects.all()
serializer_class = PostsSerializer
filter_class = PostsFilter
ordering_fields = ('created_at')
@action(methods=['patch'], detail=False)
queryset = self.filter_queryset(self.get_queryset())
serializer = self.get_serializer(instance=queryset,
data=request.data, many=True, partial=True) # add "partial=True"
valid = serializer.is_valid(raise_exception=True)
logger.error(serializer.validated_data)
self.perform_update(serializer)
return Response(serializer.data)
```
Post by h***@gmail.com
I want to conduct bulk update for Model.
I know "PUT" action can be called by specific data. So we must set a new
action for the one.
This is my source code of bulk update.
https://github.com/encode/django-rest-framework/issues/6087
But, it couldn't work.
Because "validated_data" was empty even though I couldn't use the
parameter of read-only.
I think my source code is incorrect especially creating serializer for
ListSerializer.
Please let me know and give me your advice if you have a nice idea.
Thanks.
--
You received this message because you are subscribed to the Google Groups "Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-framework+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Continue reading on narkive:
Loading...