Service Instance Update #61

Merged
rixx merged 12 commits from 29-service-instance-update into main 2025-05-21 07:39:18 +00:00
Showing only changes of commit 9830eebcda - Show all commits

View file

@ -9,6 +9,18 @@ from django.utils.translation import gettext_lazy as _
from servala.core.models import ServiceInstance
class CRDModel(models.Model):
"""Base class for all virtual CRD models"""
def __init__(self, **kwargs):
if spec := kwargs.pop("spec", None):
kwargs.update(unnest_data({"spec": spec}))
super().__init__(**kwargs)
class Meta:
abstract = True
def duplicate_field(field_name, model):
# Get the field from the model
field = model._meta.get_field(field_name)
@ -47,7 +59,7 @@ def generate_django_model(schema, group, version, kind):
# create the model class
model_name = kind
model_class = type(model_name, (models.Model,), model_fields)
model_class = type(model_name, (CRDModel,), model_fields)
return model_class
@ -138,6 +150,21 @@ def get_django_field(
return models.CharField(max_length=255, **kwargs)
def unnest_data(data):
result = {}
def _flatten_dict(d, parent_key=""):
for key, value in d.items():
new_key = f"{parent_key}.{key}" if parent_key else key
if isinstance(value, dict):
_flatten_dict(value, new_key)
else:
result[new_key] = value
_flatten_dict(data)
return result
class CrdModelFormMixin:
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)