1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Store empty names as null

This commit is contained in:
Jeremy Stretch
2020-02-07 12:24:38 -05:00
parent c72a353733
commit dc1b7874ff
3 changed files with 11 additions and 7 deletions

View File

@ -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
),
]

View File

@ -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'),

View File

@ -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():