Add name, org and context to all crd forms
This commit is contained in:
parent
57945c8e51
commit
8a1f72b317
1 changed files with 8 additions and 0 deletions
|
@ -1,10 +1,13 @@
|
|||
import re
|
||||
|
||||
from django import forms
|
||||
from django.core.validators import MaxValueValidator, MinValueValidator, RegexValidator
|
||||
from django.db import models
|
||||
from django.forms.models import ModelForm, ModelFormMetaclass
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from servala.core.models import ServiceInstance
|
||||
|
||||
|
||||
def generate_django_model(schema, group, version, kind):
|
||||
"""
|
||||
|
@ -14,6 +17,8 @@ def generate_django_model(schema, group, version, kind):
|
|||
# defaults = {"apiVersion": f"{group}/{version}", "kind": kind}
|
||||
|
||||
model_fields = {"__module__": "crd_models"}
|
||||
for field in ("name", "organization", "context"):
|
||||
model_fields[field] = ServiceInstance._meta.get_field(field)
|
||||
model_fields.update(build_object_fields(spec, "spec"))
|
||||
|
||||
meta_class = type("Meta", (), {"app_label": "crd_models"})
|
||||
|
@ -110,6 +115,9 @@ def get_django_field(
|
|||
class CrdModelFormMixin:
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
for field in ("organization", "context"):
|
||||
self.fields[field].widget = forms.HiddenInput()
|
||||
# self.fields["apiVersion"].disabled = True
|
||||
# self.fields["kind"].disabled = True
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue