-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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 #4351 from netbox-community/1754-nested-rackgroups
Closes #1754: Nested rack groups
- Loading branch information
Showing
11 changed files
with
234 additions
and
51 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,43 @@ | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import mptt.fields | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('dcim', '0100_mptt_remove_indexes'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='rackgroup', | ||
name='parent', | ||
field=mptt.fields.TreeForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='children', to='dcim.RackGroup'), | ||
), | ||
migrations.AddField( | ||
model_name='rackgroup', | ||
name='level', | ||
field=models.PositiveIntegerField(default=0, editable=False), | ||
preserve_default=False, | ||
), | ||
migrations.AddField( | ||
model_name='rackgroup', | ||
name='lft', | ||
field=models.PositiveIntegerField(default=1, editable=False), | ||
preserve_default=False, | ||
), | ||
migrations.AddField( | ||
model_name='rackgroup', | ||
name='rght', | ||
field=models.PositiveIntegerField(default=2, editable=False), | ||
preserve_default=False, | ||
), | ||
# tree_id will be set to a valid value during the following migration (which needs to be a separate migration) | ||
migrations.AddField( | ||
model_name='rackgroup', | ||
name='tree_id', | ||
field=models.PositiveIntegerField(db_index=True, default=0, editable=False), | ||
preserve_default=False, | ||
), | ||
] |
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,21 @@ | ||
from django.db import migrations | ||
|
||
|
||
def rebuild_mptt(apps, schema_editor): | ||
RackGroup = apps.get_model('dcim', 'RackGroup') | ||
for i, rackgroup in enumerate(RackGroup.objects.all(), start=1): | ||
RackGroup.objects.filter(pk=rackgroup.pk).update(tree_id=i) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('dcim', '0101_nested_rackgroups'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython( | ||
code=rebuild_mptt, | ||
reverse_code=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
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.