Add ServiceDefinition.advanced_fields

ref #204
This commit is contained in:
Tobias Kunze 2025-10-15 14:34:38 +02:00
parent 4124add146
commit cd886df05b
3 changed files with 68 additions and 1 deletions

View file

@ -318,8 +318,35 @@ class ServiceDefinitionAdmin(admin.ModelAdmin):
"description": _("API definition for the Kubernetes Custom Resource"),
},
),
(
_("Form Configuration"),
{
"fields": ("advanced_fields",),
"description": _(
"Configure which fields should be hidden behind an 'Advanced' toggle in the form"
),
},
),
)
def get_form(self, request, obj=None, **kwargs):
form = super().get_form(request, obj, **kwargs)
# JSON schema for advanced_fields field
advanced_fields_schema = {
"type": "array",
"title": "Advanced Fields",
"items": {
"type": "string",
"title": "Field Name",
"description": "Field name in dot notation (e.g., spec.parameters.monitoring.enabled)",
},
}
if "advanced_fields" in form.base_fields:
form.base_fields["advanced_fields"].widget = JSONFormWidget(
schema=advanced_fields_schema
)
return form
def get_exclude(self, request, obj=None):
# Exclude the original api_definition field as we're using our custom fields
return ["api_definition"]

View file

@ -0,0 +1,27 @@
# Generated by Django 5.2.7 on 2025-10-17 03:23
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("core", "0013_controlplane_wildcard_dns"),
]
operations = [
migrations.AddField(
model_name="servicedefinition",
name="advanced_fields",
field=models.JSONField(
blank=True,
default=list,
help_text=(
"Array of field names that should be hidden behind an 'Advanced' toggle. "
"Use dot notation (e.g., ['spec.parameters.monitoring.enabled', 'spec.parameters.backup.schedule'])"
),
null=True,
verbose_name="Advanced fields",
),
),
]

View file

@ -359,6 +359,16 @@ class ServiceDefinition(ServalaModelMixin, models.Model):
null=True,
blank=True,
)
advanced_fields = models.JSONField(
verbose_name=_("Advanced fields"),
help_text=_(
"Array of field names that should be hidden behind an 'Advanced' toggle. "
"Use dot notation (e.g., ['spec.parameters.monitoring.enabled', 'spec.parameters.backup.schedule'])"
),
null=True,
blank=True,
default=list,
)
service = models.ForeignKey(
to="Service",
on_delete=models.CASCADE,
@ -499,7 +509,10 @@ class ControlPlaneCRD(ServalaModelMixin, models.Model):
if not self.django_model:
return
return generate_model_form_class(self.django_model)
advanced_fields = self.service_definition.advanced_fields or []
return generate_model_form_class(
self.django_model, advanced_fields=advanced_fields
)
class ServiceOffering(ServalaModelMixin, models.Model):