-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #139 from maykinmedia/feature/records-with-index
Feature/records with index
- Loading branch information
Showing
11 changed files
with
146 additions
and
89 deletions.
There are no files selected for viewing
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
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
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
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,24 @@ | ||
# Generated by Django 2.2.12 on 2021-01-13 11:39 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("core", "0017_auto_20210111_1653"), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name="objectrecord", | ||
name="uuid", | ||
), | ||
migrations.AddField( | ||
model_name="objectrecord", | ||
name="index", | ||
field=models.PositiveIntegerField( | ||
default=1, help_text="Incremental index number of the object record." | ||
), | ||
), | ||
] |
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,32 @@ | ||
from django.db import migrations | ||
from django.db.models.expressions import Window | ||
from django.db.models.functions import RowNumber | ||
from django.db.models import F | ||
|
||
|
||
def fill_record_index(apps, _): | ||
ObjectRecord = apps.get_model("core", "ObjectRecord") | ||
|
||
records = ObjectRecord.objects.annotate( | ||
row_number=Window( | ||
expression=RowNumber(), | ||
partition_by=[F("object")], | ||
order_by=[F("start_at"), F("id")], | ||
) | ||
).order_by("object") | ||
|
||
for record in records: | ||
if record.index != record.row_number: | ||
record.index = record.row_number | ||
record.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("core", "0018_auto_20210113_1239"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(fill_record_index, migrations.RunPython.noop), | ||
] |
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
Oops, something went wrong.