diff --git a/netbox/dcim/migrations/0095_primary_model_ordering.py b/netbox/dcim/migrations/0095_primary_model_ordering.py index 7a04aa31d..9cef0a581 100644 --- a/netbox/dcim/migrations/0095_primary_model_ordering.py +++ b/netbox/dcim/migrations/0095_primary_model_ordering.py @@ -43,7 +43,7 @@ class Migration(migrations.Migration): migrations.AddField( model_name='device', name='_name', - field=utilities.fields.NaturalOrderingField('target_field', blank=True, max_length=100, naturalize_function=utilities.ordering.naturalize), + field=utilities.fields.NaturalOrderingField('target_field', blank=True, max_length=100, naturalize_function=utilities.ordering.naturalize, null=True), ), migrations.AddField( model_name='rack', @@ -56,12 +56,15 @@ class Migration(migrations.Migration): field=utilities.fields.NaturalOrderingField('target_field', blank=True, max_length=100, naturalize_function=utilities.ordering.naturalize), ), migrations.RunPython( - code=naturalize_sites + code=naturalize_sites, + reverse_code=migrations.RunPython.noop ), migrations.RunPython( - code=naturalize_racks + code=naturalize_racks, + reverse_code=migrations.RunPython.noop ), migrations.RunPython( - code=naturalize_devices + code=naturalize_devices, + reverse_code=migrations.RunPython.noop ), ] diff --git a/netbox/dcim/models/__init__.py b/netbox/dcim/models/__init__.py index 9b9252bef..c31f4c713 100644 --- a/netbox/dcim/models/__init__.py +++ b/netbox/dcim/models/__init__.py @@ -1321,7 +1321,8 @@ class Device(ChangeLoggedModel, ConfigContextModel, CustomFieldModel): _name = NaturalOrderingField( target_field='name', max_length=100, - blank=True + blank=True, + null=True ) serial = models.CharField( max_length=50, @@ -1438,7 +1439,7 @@ class Device(ChangeLoggedModel, ConfigContextModel, CustomFieldModel): } class Meta: - ordering = ('_name', 'pk') # Name may be blank + ordering = ('_name', 'pk') # Name may be null unique_together = ( ('site', 'tenant', 'name'), # See validate_unique below ('rack', 'position', 'face'), diff --git a/netbox/utilities/ordering.py b/netbox/utilities/ordering.py index fd3010e90..88a46d3d3 100644 --- a/netbox/utilities/ordering.py +++ b/netbox/utilities/ordering.py @@ -21,7 +21,7 @@ def naturalize(value, max_length=None, integer_places=8): :param integer_places: The number of places to which each integer will be expanded. (Default: 8) """ if not value: - return '' + return value output = [] for segment in re.split(r'(\d+)', value): if segment.isdigit():