Skip to content

Instantly share code, notes, and snippets.

@icarovirtual
Last active October 19, 2019 13:38
Show Gist options
  • Select an option

  • Save icarovirtual/817125e1f4fa4de381f106cf2361f956 to your computer and use it in GitHub Desktop.

Select an option

Save icarovirtual/817125e1f4fa4de381f106cf2361f956 to your computer and use it in GitHub Desktop.

Revisions

  1. icarovirtual revised this gist Oct 19, 2019. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion copy_queryset_without_annotations.py
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,4 @@
    def copy_queryset_without_annotations(original_qs):
    """ Create a new queryset copying the filters but without annotations. """
    # Create a new queryset based on the same model
    optimized_qs = original_qs.model.objects.all()
    # Copy the filters
  2. icarovirtual revised this gist Oct 7, 2019. No changes.
  3. icarovirtual created this gist Oct 7, 2019.
    8 changes: 8 additions & 0 deletions copy_queryset_without_annotations.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    def copy_queryset_without_annotations(original_qs):
    """ Create a new queryset copying the filters but without annotations. """
    # 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