Closes #17761: Store empty CharField choices as null

This commit is contained in:
Jeremy Stretch
2024-10-18 16:55:58 -04:00
parent 75270c1aef
commit ef1fdf0a01
23 changed files with 622 additions and 25 deletions

View File

@@ -0,0 +1,49 @@
from django.db import migrations, models
def set_null_values(apps, schema_editor):
"""
Replace empty strings with null values.
"""
IKEPolicy = apps.get_model('vpn', 'IKEPolicy')
IKEProposal = apps.get_model('vpn', 'IKEProposal')
IPSecProposal = apps.get_model('vpn', 'IPSecProposal')
IKEPolicy.objects.filter(mode='').update(mode=None)
IKEProposal.objects.filter(authentication_algorithm='').update(authentication_algorithm=None)
IPSecProposal.objects.filter(authentication_algorithm='').update(authentication_algorithm=None)
IPSecProposal.objects.filter(encryption_algorithm='').update(encryption_algorithm=None)
class Migration(migrations.Migration):
dependencies = [
('vpn', '0005_rename_indexes'),
]
operations = [
migrations.AlterField(
model_name='ikepolicy',
name='mode',
field=models.CharField(blank=True, null=True),
),
migrations.AlterField(
model_name='ikeproposal',
name='authentication_algorithm',
field=models.CharField(blank=True, null=True),
),
migrations.AlterField(
model_name='ipsecproposal',
name='authentication_algorithm',
field=models.CharField(blank=True, null=True),
),
migrations.AlterField(
model_name='ipsecproposal',
name='encryption_algorithm',
field=models.CharField(blank=True, null=True),
),
migrations.RunPython(
code=set_null_values,
reverse_code=migrations.RunPython.noop
),
]

View File

@@ -35,7 +35,8 @@ class IKEProposal(PrimaryModel):
authentication_algorithm = models.CharField(
verbose_name=_('authentication algorithm'),
choices=AuthenticationAlgorithmChoices,
blank=True
blank=True,
null=True
)
group = models.PositiveSmallIntegerField(
verbose_name=_('group'),
@@ -76,7 +77,8 @@ class IKEPolicy(PrimaryModel):
mode = models.CharField(
verbose_name=_('mode'),
choices=IKEModeChoices,
blank=True
blank=True,
null=True
)
proposals = models.ManyToManyField(
to='vpn.IKEProposal',
@@ -128,12 +130,14 @@ class IPSecProposal(PrimaryModel):
encryption_algorithm = models.CharField(
verbose_name=_('encryption'),
choices=EncryptionAlgorithmChoices,
blank=True
blank=True,
null=True
)
authentication_algorithm = models.CharField(
verbose_name=_('authentication'),
choices=AuthenticationAlgorithmChoices,
blank=True
blank=True,
null=True
)
sa_lifetime_seconds = models.PositiveIntegerField(
verbose_name=_('SA lifetime (seconds)'),