From 7de3921c395c55f9669ec11790ecaa0c7cda463a Mon Sep 17 00:00:00 2001 From: "Jean Cochrane (Lead developer, DataMade)" Date: Tue, 15 Oct 2019 09:17:15 -0500 Subject: [PATCH] Ensure clean_locations iterates all Locations --- sfm_pc/management/commands/clean_locations.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sfm_pc/management/commands/clean_locations.py b/sfm_pc/management/commands/clean_locations.py index 2f3d984fe..4b71a1e66 100644 --- a/sfm_pc/management/commands/clean_locations.py +++ b/sfm_pc/management/commands/clean_locations.py @@ -34,10 +34,11 @@ def handle(self, *args, **options): ).delete() else: num_deleted = 0 - paginator = Paginator(Location.objects.all().order_by('id'), 50) + batch_size = 100 + page_range = (location_count//batch_size)+1 with tqdm(total=location_count) as progress_bar: - for page in paginator.page_range: - for location in paginator.page(page).object_list: + for page in range(page_range): + for location in Location.objects.all()[:batch_size]: if not location.related_entities: location.delete() num_deleted += 1