mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-24 17:38:37 -06:00
Store empty names as null
This commit is contained in:
parent
c72a353733
commit
dc1b7874ff
@ -43,7 +43,7 @@ class Migration(migrations.Migration):
|
|||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='device',
|
model_name='device',
|
||||||
name='_name',
|
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(
|
migrations.AddField(
|
||||||
model_name='rack',
|
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),
|
field=utilities.fields.NaturalOrderingField('target_field', blank=True, max_length=100, naturalize_function=utilities.ordering.naturalize),
|
||||||
),
|
),
|
||||||
migrations.RunPython(
|
migrations.RunPython(
|
||||||
code=naturalize_sites
|
code=naturalize_sites,
|
||||||
|
reverse_code=migrations.RunPython.noop
|
||||||
),
|
),
|
||||||
migrations.RunPython(
|
migrations.RunPython(
|
||||||
code=naturalize_racks
|
code=naturalize_racks,
|
||||||
|
reverse_code=migrations.RunPython.noop
|
||||||
),
|
),
|
||||||
migrations.RunPython(
|
migrations.RunPython(
|
||||||
code=naturalize_devices
|
code=naturalize_devices,
|
||||||
|
reverse_code=migrations.RunPython.noop
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
@ -1321,7 +1321,8 @@ class Device(ChangeLoggedModel, ConfigContextModel, CustomFieldModel):
|
|||||||
_name = NaturalOrderingField(
|
_name = NaturalOrderingField(
|
||||||
target_field='name',
|
target_field='name',
|
||||||
max_length=100,
|
max_length=100,
|
||||||
blank=True
|
blank=True,
|
||||||
|
null=True
|
||||||
)
|
)
|
||||||
serial = models.CharField(
|
serial = models.CharField(
|
||||||
max_length=50,
|
max_length=50,
|
||||||
@ -1438,7 +1439,7 @@ class Device(ChangeLoggedModel, ConfigContextModel, CustomFieldModel):
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ('_name', 'pk') # Name may be blank
|
ordering = ('_name', 'pk') # Name may be null
|
||||||
unique_together = (
|
unique_together = (
|
||||||
('site', 'tenant', 'name'), # See validate_unique below
|
('site', 'tenant', 'name'), # See validate_unique below
|
||||||
('rack', 'position', 'face'),
|
('rack', 'position', 'face'),
|
||||||
|
@ -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)
|
:param integer_places: The number of places to which each integer will be expanded. (Default: 8)
|
||||||
"""
|
"""
|
||||||
if not value:
|
if not value:
|
||||||
return ''
|
return value
|
||||||
output = []
|
output = []
|
||||||
for segment in re.split(r'(\d+)', value):
|
for segment in re.split(r'(\d+)', value):
|
||||||
if segment.isdigit():
|
if segment.isdigit():
|
||||||
|
Loading…
Reference in New Issue
Block a user