Skip to content

Commit

Permalink
publications: Initialize sort order
Browse files Browse the repository at this point in the history
Add data migration to initialize the sort order with initial values
which result in the publications being shown in the same order as
before. We change the order from '-pk' to 'sort_order'. Initialize
sort_order with -pk to get the same initial order.
  • Loading branch information
donald committed Aug 2, 2021
1 parent b2ddc41 commit 9c28f4d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions mpicms/publications/migrations/0004_publication_sort_order.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Generated by Django 2.2.9 on 2020-01-19 19:36

from django.db import migrations, models

def init_sort_order(apps, schema_editor):
Publication = apps.get_model('publications', 'Publication')
for publication in Publication.objects.all():
publication.sort_order = -publication.pk
publication.save(update_fields=['sort_order'])

class Migration(migrations.Migration):

Expand All @@ -15,4 +18,5 @@ class Migration(migrations.Migration):
name='sort_order',
field=models.IntegerField(blank=True, editable=False, null=True),
),
migrations.RunPython(init_sort_order, reverse_code=migrations.RunPython.noop),
]

0 comments on commit 9c28f4d

Please sign in to comment.