diff --git a/datacenterlight/cms_models.py b/datacenterlight/cms_models.py index deb84dc7..8c31696f 100644 --- a/datacenterlight/cms_models.py +++ b/datacenterlight/cms_models.py @@ -300,20 +300,6 @@ class MultipleChoiceArrayField(ArrayField): Uses Django's Postgres ArrayField and a MultipleChoiceField for its formfield. """ - - def formfield(self, **kwargs): - defaults = { - 'form_class': forms.MultipleChoiceField, - 'choices': self.base_field.choices, - } - defaults.update(kwargs) - # Skip our parent's formfield implementation completely as we don't - # care for it. - # pylint:disable=bad-super-call - return super(ArrayField, self).formfield(**defaults) - - -class DCLCalculatorPluginModel(CMSPlugin): VMTemplateChoices = list( ( str(obj.opennebula_vm_template_id), @@ -323,6 +309,20 @@ class DCLCalculatorPluginModel(CMSPlugin): ) for obj in VMTemplate.objects.all() ) + + def formfield(self, **kwargs): + defaults = { + 'form_class': forms.MultipleChoiceField, + 'choices': self.VMTemplateChoices, + } + defaults.update(kwargs) + # Skip our parent's formfield implementation completely as we don't + # care for it. + # pylint:disable=bad-super-call + return super(ArrayField, self).formfield(**defaults) + + +class DCLCalculatorPluginModel(CMSPlugin): pricing = models.ForeignKey( VMPricing, related_name="dcl_custom_pricing_vm_pricing", @@ -337,7 +337,6 @@ class DCLCalculatorPluginModel(CMSPlugin): base_field=models.CharField( blank=True, max_length=256, - choices=VMTemplateChoices ), default=list, blank=True, diff --git a/datacenterlight/migrations/0024_dclcalculatorpluginmodel_vm_templates_to_show.py b/datacenterlight/migrations/0024_dclcalculatorpluginmodel_vm_templates_to_show.py index 179dcff9..65bfce21 100644 --- a/datacenterlight/migrations/0024_dclcalculatorpluginmodel_vm_templates_to_show.py +++ b/datacenterlight/migrations/0024_dclcalculatorpluginmodel_vm_templates_to_show.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Generated by Django 1.9.4 on 2018-06-24 06:54 +# Generated by Django 1.9.4 on 2018-06-24 08:23 from __future__ import unicode_literals import datacenterlight.cms_models @@ -16,6 +16,6 @@ class Migration(migrations.Migration): migrations.AddField( model_name='dclcalculatorpluginmodel', name='vm_templates_to_show', - field=datacenterlight.cms_models.MultipleChoiceArrayField(base_field=models.CharField(blank=True, choices=[('4', 'CentOS 7'), ('14', 'Debian 8'), ('25', 'Ubuntu 14.04'), ('26', 'Ubuntu 16.04'), ('36', 'Devuan Jessie'), ('65', 'Devuan Ascii'), ('69', 'FreeBSD 11.1')], max_length=256), blank=True, default=list, help_text='Recommended: If you wish to show all templates of the corresponding VM Type (public/ipv6only), please do not select any of the items in the above field. This will allow any new template(s) added in the backend to be automatically listed in this calculator instance.', size=None), + field=datacenterlight.cms_models.MultipleChoiceArrayField(base_field=models.CharField(blank=True, max_length=256), blank=True, default=list, help_text='Recommended: If you wish to show all templates of the corresponding VM Type (public/ipv6only), please do not select any of the items in the above field. This will allow any new template(s) added in the backend to be automatically listed in this calculator instance.', size=None), ), ]