mirror of
https://github.com/netbox-community/netbox.git
synced 2026-01-22 19:48:45 -06:00
Closes #17761: Store empty CharField choices as null
This commit is contained in:
29
netbox/tenancy/migrations/0016_charfield_null_choices.py
Normal file
29
netbox/tenancy/migrations/0016_charfield_null_choices.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
def set_null_values(apps, schema_editor):
|
||||
"""
|
||||
Replace empty strings with null values.
|
||||
"""
|
||||
ContactAssignment = apps.get_model('tenancy', 'ContactAssignment')
|
||||
|
||||
ContactAssignment.objects.filter(priority='').update(priority=None)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('tenancy', '0015_contactassignment_rename_content_type'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='contactassignment',
|
||||
name='priority',
|
||||
field=models.CharField(blank=True, max_length=50, null=True),
|
||||
),
|
||||
migrations.RunPython(
|
||||
code=set_null_values,
|
||||
reverse_code=migrations.RunPython.noop
|
||||
),
|
||||
]
|
||||
@@ -125,7 +125,8 @@ class ContactAssignment(CustomFieldsMixin, ExportTemplatesMixin, TagsMixin, Chan
|
||||
verbose_name=_('priority'),
|
||||
max_length=50,
|
||||
choices=ContactPriorityChoices,
|
||||
blank=True
|
||||
blank=True,
|
||||
null=True
|
||||
)
|
||||
|
||||
clone_fields = ('object_type', 'object_id', 'role', 'priority')
|
||||
|
||||
Reference in New Issue
Block a user