diff --git a/program/migrations/0103_alter_radiosettings_fallback_default_pool.py b/program/migrations/0103_alter_radiosettings_fallback_default_pool.py new file mode 100644 index 0000000000000000000000000000000000000000..731a56afd5829abc690179a71c202597ee7875db --- /dev/null +++ b/program/migrations/0103_alter_radiosettings_fallback_default_pool.py @@ -0,0 +1,23 @@ +# Generated by Django 4.2.13 on 2024-06-25 20:00 + +import program.models +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("program", "0102_radiosettings_fallback_pools"), + ] + + operations = [ + migrations.AlterField( + model_name="radiosettings", + name="fallback_default_pool", + field=models.CharField( + blank=True, + max_length=32, + validators=[program.models.validate_fallback_default_pool], + ), + ), + ] diff --git a/program/models.py b/program/models.py index 8d38556d711572403b65b5e7008965303fb09a8a..44002ed8ef91b9026aa94a253628cb71017f68c2 100644 --- a/program/models.py +++ b/program/models.py @@ -617,6 +617,11 @@ def validate_fallback_pools(value): validate_value(value, schema) +def validate_fallback_default_pool(value): + if value not in RadioSettings.objects.first().fallback_pools.values(): + raise DjangoValidationError(f"Pool '{value}' does not exist in fallback pools.") + + class RadioSettings(models.Model): cba_api_key = models.CharField(blank=True, max_length=64, verbose_name="CBA API key") cba_domains = models.JSONField( @@ -626,7 +631,9 @@ class RadioSettings(models.Model): validators=[validate_cba_domains], verbose_name="CBA domains", ) - fallback_default_pool = models.CharField(blank=True, max_length=32) + fallback_default_pool = models.CharField( + blank=True, max_length=32, validators=[validate_fallback_default_pool] + ) fallback_pools = models.JSONField( blank=True, default=dict,