mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-14 01:41:22 -06:00

Made DeviceRoles hierarchical, had to also change the filtersets for Device, ConfigContext and VirtualMachine to use the TreeNodeMultipleChoiceFilter. Note: The model was changed to use NestedGroupModel, a side-effect of this is it also adds comments field, but I thought that was better then doing a one-off just for DeviceRole and having to define the fields, validators, etc.. - keeps everything DRY / consistent. * 18981 Make Device Roles Hierarchical * 18981 forms, serializer * 18981 fix tests * 18981 fix tests * 18981 fix tests * 18981 fix tests * 18981 fix tests * 18981 fix migration merge * 18981 fix tests * 18981 fix filtersets * 18981 fix tests * 18981 comments * 18981 review changes
23 lines
569 B
Python
23 lines
569 B
Python
from django.db import migrations
|
|
import mptt
|
|
import mptt.managers
|
|
|
|
|
|
def rebuild_mptt(apps, schema_editor):
|
|
manager = mptt.managers.TreeManager()
|
|
DeviceRole = apps.get_model('dcim', 'DeviceRole')
|
|
manager.model = DeviceRole
|
|
mptt.register(DeviceRole)
|
|
manager.contribute_to_class(DeviceRole, 'objects')
|
|
manager.rebuild()
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
dependencies = [
|
|
('dcim', '0203_device_role_nested'),
|
|
]
|
|
|
|
operations = [
|
|
migrations.RunPython(code=rebuild_mptt, reverse_code=migrations.RunPython.noop),
|
|
]
|