-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add migration to invert the sort_order field on featured pages
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
programs/migrations/0022_reverse_featured_pages_sort_order.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Generated by Django 3.2.18 on 2024-03-08 19:16 | ||
|
||
from django.db import migrations | ||
|
||
|
||
def reverse_featured_pages(apps, schema_editor): | ||
FeaturedProgramPage = apps.get_model('programs', 'FeaturedProgramPage') | ||
Program = apps.get_model('programs', 'Program') | ||
|
||
for program in Program.objects.all(): | ||
items_to_update = [] | ||
if not program.featured_pages.exclude(sort_order__isnull=True).exists(): | ||
continue | ||
for i, featured_page in enumerate(program.featured_pages.order_by('-sort_order')): | ||
featured_page.sort_order = i | ||
items_to_update.append(featured_page) | ||
FeaturedProgramPage.objects.bulk_update( | ||
items_to_update, | ||
['sort_order'], | ||
) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('programs', '0021_remove_legacy_subscribe_page_models'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(reverse_featured_pages), | ||
] |