diff --git a/InvenTree/InvenTree/models.py b/InvenTree/InvenTree/models.py index f7d1670b8a..d5b1cddc17 100644 --- a/InvenTree/InvenTree/models.py +++ b/InvenTree/InvenTree/models.py @@ -48,11 +48,11 @@ class InvenTreeTree(MPTTModel): ) # When a category is deleted, graft the children onto its parent - parent = models.ForeignKey('self', - on_delete=models.DO_NOTHING, - blank=True, - null=True, - related_name='children') + parent = TreeForeignKey('self', + on_delete=models.DO_NOTHING, + blank=True, + null=True, + related_name='children') @property def item_count(self): diff --git a/InvenTree/part/migrations/0021_auto_20190908_0916.py b/InvenTree/part/migrations/0021_auto_20190908_0916.py new file mode 100644 index 0000000000..0427487246 --- /dev/null +++ b/InvenTree/part/migrations/0021_auto_20190908_0916.py @@ -0,0 +1,30 @@ +# Generated by Django 2.2.5 on 2019-09-08 09:16 + +from django.db import migrations +import django.db.models.deletion +import mptt.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('part', '0020_auto_20190908_0404'), + ] + + operations = [ + migrations.AlterField( + model_name='part', + name='category', + field=mptt.fields.TreeForeignKey(blank=True, help_text='Part category', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='parts', to='part.PartCategory'), + ), + migrations.AlterField( + model_name='part', + name='default_location', + field=mptt.fields.TreeForeignKey(blank=True, help_text='Where is this item normally stored?', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='default_parts', to='stock.StockLocation'), + ), + migrations.AlterField( + model_name='partcategory', + name='default_location', + field=mptt.fields.TreeForeignKey(blank=True, help_text='Default location for parts in this category', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='default_categories', to='stock.StockLocation'), + ), + ] diff --git a/InvenTree/part/migrations/0022_auto_20190908_0918.py b/InvenTree/part/migrations/0022_auto_20190908_0918.py new file mode 100644 index 0000000000..48782ed545 --- /dev/null +++ b/InvenTree/part/migrations/0022_auto_20190908_0918.py @@ -0,0 +1,20 @@ +# Generated by Django 2.2.5 on 2019-09-08 09:18 + +from django.db import migrations +import django.db.models.deletion +import mptt.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('part', '0021_auto_20190908_0916'), + ] + + operations = [ + migrations.AlterField( + model_name='partcategory', + name='parent', + field=mptt.fields.TreeForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='children', to='part.PartCategory'), + ), + ] diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 2970129d6e..7cf6776b1d 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -25,6 +25,8 @@ from django.contrib.auth.models import User from django.db.models.signals import pre_delete from django.dispatch import receiver +from mptt.models import TreeForeignKey + from datetime import datetime from fuzzywuzzy import fuzz import hashlib @@ -48,7 +50,7 @@ class PartCategory(InvenTreeTree): default_keywords: Default keywords for parts created in this category """ - default_location = models.ForeignKey( + default_location = TreeForeignKey( 'stock.StockLocation', related_name="default_categories", null=True, blank=True, on_delete=models.SET_NULL, @@ -351,10 +353,10 @@ class Part(models.Model): keywords = models.CharField(max_length=250, blank=True, help_text='Part keywords to improve visibility in search results') - category = models.ForeignKey(PartCategory, related_name='parts', - null=True, blank=True, - on_delete=models.DO_NOTHING, - help_text='Part category') + category = TreeForeignKey(PartCategory, related_name='parts', + null=True, blank=True, + on_delete=models.DO_NOTHING, + help_text='Part category') IPN = models.CharField(max_length=100, blank=True, help_text='Internal Part Number') @@ -364,10 +366,10 @@ class Part(models.Model): image = models.ImageField(upload_to=rename_part_image, max_length=255, null=True, blank=True) - default_location = models.ForeignKey('stock.StockLocation', on_delete=models.SET_NULL, - blank=True, null=True, - help_text='Where is this item normally stored?', - related_name='default_parts') + default_location = TreeForeignKey('stock.StockLocation', on_delete=models.SET_NULL, + blank=True, null=True, + help_text='Where is this item normally stored?', + related_name='default_parts') def get_default_location(self): """ Get the default location for a Part (may be None). diff --git a/InvenTree/stock/migrations/0013_auto_20190908_0916.py b/InvenTree/stock/migrations/0013_auto_20190908_0916.py new file mode 100644 index 0000000000..897d4298c2 --- /dev/null +++ b/InvenTree/stock/migrations/0013_auto_20190908_0916.py @@ -0,0 +1,20 @@ +# Generated by Django 2.2.5 on 2019-09-08 09:16 + +from django.db import migrations +import django.db.models.deletion +import mptt.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('stock', '0012_auto_20190908_0405'), + ] + + operations = [ + migrations.AlterField( + model_name='stockitem', + name='location', + field=mptt.fields.TreeForeignKey(blank=True, help_text='Where is this stock item located?', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='stock_items', to='stock.StockLocation'), + ), + ] diff --git a/InvenTree/stock/migrations/0014_auto_20190908_0918.py b/InvenTree/stock/migrations/0014_auto_20190908_0918.py new file mode 100644 index 0000000000..b6f7411e10 --- /dev/null +++ b/InvenTree/stock/migrations/0014_auto_20190908_0918.py @@ -0,0 +1,20 @@ +# Generated by Django 2.2.5 on 2019-09-08 09:18 + +from django.db import migrations +import django.db.models.deletion +import mptt.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('stock', '0013_auto_20190908_0916'), + ] + + operations = [ + migrations.AlterField( + model_name='stocklocation', + name='parent', + field=mptt.fields.TreeForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='children', to='stock.StockLocation'), + ), + ] diff --git a/InvenTree/stock/models.py b/InvenTree/stock/models.py index 889eaac5bd..6c4571d5a3 100644 --- a/InvenTree/stock/models.py +++ b/InvenTree/stock/models.py @@ -16,6 +16,8 @@ from django.contrib.auth.models import User from django.db.models.signals import pre_delete from django.dispatch import receiver +from mptt.models import TreeForeignKey + from datetime import datetime from InvenTree import helpers @@ -292,9 +294,9 @@ class StockItem(models.Model): supplier_part = models.ForeignKey('company.SupplierPart', blank=True, null=True, on_delete=models.SET_NULL, help_text='Select a matching supplier part for this stock item') - location = models.ForeignKey(StockLocation, on_delete=models.DO_NOTHING, - related_name='stock_items', blank=True, null=True, - help_text='Where is this stock item located?') + location = TreeForeignKey(StockLocation, on_delete=models.DO_NOTHING, + related_name='stock_items', blank=True, null=True, + help_text='Where is this stock item located?') belongs_to = models.ForeignKey('self', on_delete=models.DO_NOTHING, related_name='owned_parts', blank=True, null=True,