-
-
Notifications
You must be signed in to change notification settings - Fork 763
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update BomItem 'validated' field (#4486)
* Adds new "validated" field to the BomItem model - Previously this was dynamically calculated (very expensive) - Now cached and updated whenever a BomItem instance is saved - Will make the BOM API much more responsive - Cleanup BomItem list API code also * Adds data migration to update existing BomItem objects * Exclude 'validated' field from BomItemResource class
- Loading branch information
1 parent
06f8a50
commit 1ba51e5
Showing
6 changed files
with
84 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 3.2.18 on 2023-03-14 01:08 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('part', '0100_alter_bomitem_reference'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='bomitem', | ||
name='validated', | ||
field=models.BooleanField(default=False, help_text='This BOM item has been validated', verbose_name='Validated'), | ||
), | ||
] |
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,40 @@ | ||
# Generated by Django 3.2.18 on 2023-03-14 01:12 | ||
|
||
import logging | ||
|
||
from django.db import migrations | ||
|
||
|
||
logger = logging.getLogger('inventree') | ||
|
||
|
||
def update_bom_item(apps, schema_editor): | ||
"""Update all existing BomItem instances""" | ||
|
||
from part.models import BomItem | ||
|
||
if n := BomItem.objects.count(): | ||
|
||
for item in BomItem.objects.all(): | ||
item.save() | ||
|
||
logger.info(f"Updated 'validated' flag for {n} BomItem objects") | ||
|
||
|
||
def meti_mob_etadpu(apps, schema_editor): | ||
"""Provided for reverse compatibility""" | ||
pass | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('part', '0101_bomitem_validated'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython( | ||
update_bom_item, | ||
reverse_code=meti_mob_etadpu | ||
) | ||
] |
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