fix virtual machine serializer e.t.c

This commit is contained in:
bruks 2026-09-30 16:25:14 +01:00
commit 6b21b86ffe
5 changed files with 62 additions and 23 deletions

View file

@ -307,30 +307,35 @@ class DCLSectionPromoPluginModel(CMSPlugin):
class MultipleChoiceArrayField(ArrayField):
"""
A field that allows us to store an array of choices.
Uses Django's Postgres ArrayField
and a MultipleChoiceField for its formfield.
"""
VMTemplateChoices = []
if settings.OPENNEBULA_DOMAIN != 'test_domain':
VMTemplateChoices = list(
(
str(obj.opennebula_vm_template_id),
(obj.name + ' - ' + VMTemplate.IPV6.title()
if obj.vm_type == VMTemplate.IPV6 else obj.name
)
)
for obj in VMTemplate.objects.all()
)
def formfield(self, **kwargs):
vm_template_choices = []
if settings.OPENNEBULA_DOMAIN != 'test_domain':
vm_template_choices = [
(
str(obj.opennebula_vm_template_id),
(
obj.name + ' - ' + VMTemplate.IPV6.title()
if obj.vm_type == VMTemplate.IPV6
else obj.name
),
)
for obj in VMTemplate.objects.all()
]
defaults = {
'form_class': forms.MultipleChoiceField,
'choices': self.VMTemplateChoices,
'choices': vm_template_choices,
}
defaults.update(kwargs)
# Skip our parent's formfield implementation completely as we don't
# care for it.
# pylint:disable=bad-super-call
# Skip ArrayField.formfield() because we don't need its implementation.
return super(ArrayField, self).formfield(**defaults)