Restructure form data into JSON object
This commit is contained in:
parent
2f607f8271
commit
174837a870
1 changed files with 26 additions and 2 deletions
|
@ -133,8 +133,32 @@ class CrdModelFormMixin:
|
||||||
|
|
||||||
for field in ("organization", "context"):
|
for field in ("organization", "context"):
|
||||||
self.fields[field].widget = forms.HiddenInput()
|
self.fields[field].widget = forms.HiddenInput()
|
||||||
# self.fields["apiVersion"].disabled = True
|
|
||||||
# self.fields["kind"].disabled = True
|
def get_nested_data(self):
|
||||||
|
"""
|
||||||
|
Builds the original nested JSON structure from flat form data.
|
||||||
|
Form fields are named with dot notation (e.g., 'spec.replicas')
|
||||||
|
"""
|
||||||
|
result = {}
|
||||||
|
|
||||||
|
for field_name, value in self.cleaned_data.items():
|
||||||
|
if value is None or value == "":
|
||||||
|
continue
|
||||||
|
|
||||||
|
parts = field_name.split(".")
|
||||||
|
current = result
|
||||||
|
|
||||||
|
# Navigate through the nested structure
|
||||||
|
for i, part in enumerate(parts):
|
||||||
|
if i == len(parts) - 1:
|
||||||
|
# Last part, set the value
|
||||||
|
current[part] = value
|
||||||
|
else:
|
||||||
|
# Create nested dict if it doesn't exist
|
||||||
|
if part not in current:
|
||||||
|
current[part] = {}
|
||||||
|
current = current[part]
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
def generate_model_form_class(model):
|
def generate_model_form_class(model):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue