Skip to content

Commit 7de3921

Browse files
author
Jean Cochrane (Lead developer, DataMade)
committed
Ensure clean_locations iterates all Locations
1 parent 92e6d31 commit 7de3921

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

sfm_pc/management/commands/clean_locations.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ def handle(self, *args, **options):
3434
).delete()
3535
else:
3636
num_deleted = 0
37-
paginator = Paginator(Location.objects.all().order_by('id'), 50)
37+
batch_size = 100
38+
page_range = (location_count//batch_size)+1
3839
with tqdm(total=location_count) as progress_bar:
39-
for page in paginator.page_range:
40-
for location in paginator.page(page).object_list:
40+
for page in range(page_range):
41+
for location in Location.objects.all()[:batch_size]:
4142
if not location.related_entities:
4243
location.delete()
4344
num_deleted += 1

0 commit comments

Comments
 (0)