From fd3cb6a1d4ec4b7ab8965fcd128755da26288f62 Mon Sep 17 00:00:00 2001 From: Tobias Kunze Date: Wed, 21 May 2025 09:17:09 +0200 Subject: [PATCH] Instantiate dynamic model from instance --- src/servala/core/models/service.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/servala/core/models/service.py b/src/servala/core/models/service.py index fd082ce..901a822 100644 --- a/src/servala/core/models/service.py +++ b/src/servala/core/models/service.py @@ -651,6 +651,20 @@ class ServiceInstance(ServalaModelMixin, models.Model): spec.pop("writeConnectionSecretToRef", None) return spec + @cached_property + def spec_object(self): + """Dynamically generated CRD object.""" + return self.context.django_model( + name=self.name, + organization=self.organization, + context=self.context, + spec=self.spec, + # We pass -1 as ID in order to make it clear that a) this object exists (remotely), + # and b) it’s not a normal database object. This allows us to treat e.g. update + # forms differently from create forms. + pk=-1, + ) + @cached_property def status_conditions(self): if not self.kubernetes_object: