Skip to content

Instantly share code, notes, and snippets.

@icarovirtual
Last active October 19, 2019 13:38
Show Gist options
  • Save icarovirtual/817125e1f4fa4de381f106cf2361f956 to your computer and use it in GitHub Desktop.
Save icarovirtual/817125e1f4fa4de381f106cf2361f956 to your computer and use it in GitHub Desktop.
copy_queryset_without_annotations: final investigation
def copy_queryset_without_annotations(original_qs):
# Create a new queryset based on the same model
optimized_qs = original_qs.model.objects.all()
# Copy the filters
optimized_qs.query.where = original_qs.query.where
optimized_qs.query.where_class = original_qs.query.where_class
return optimized_qs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment