You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was looking for a bulk create and a bulk delete option for DRF. I see that in the code there is a bulk create and a bulk update. Would it be possible to add a bulk create too, that uses the validation from a serializer?
I am not sure how this would look like, but I guess it would look something like
classListCreateModelMixin(BulkOperationBaseMixin):
defcreate(self, request, *args, **kwargs):
ifself.is_object_operation():
returnsuper().create(request, *args, **kwargs)
else:
returnself.create_bulk(request, *args, **kwargs)
defcreate_bulk(self, request, *args, **kwargs):
is_valid, errors=self.is_valid_bulk_operation()
ifis_valid:
queryset=self.filter_queryset(self.get_queryset())
self.pre_create_bulk(queryset)
serializer=self.get_serializer(data=request.data, many=True)
serializer.is_valid(raise_exception=True)
self.perform_bulk_create(serializer)
self.post_create_bulk(queryset)
returnResponse(status=status.HTTP_204_NO_CONTENT)
else:
returnResponse(errors, status=status.HTTP_400_BAD_REQUEST)
defperform_bulk_create(self, serializer):
serializer.save()
defpre_create_bulk(self, queryset):
""" Placeholder method for calling before creating an queryset. """passdefpost_create_bulk(self, queryset):
""" Placeholder method for calling after creating an queryset. """pass
The text was updated successfully, but these errors were encountered:
I was looking for a bulk create and a bulk delete option for DRF. I see that in the code there is a bulk create and a bulk update. Would it be possible to add a bulk create too, that uses the validation from a serializer?
I am not sure how this would look like, but I guess it would look something like
The text was updated successfully, but these errors were encountered: