From 139aca6a61879cebc4dc07ec782782d82ed0c2fe Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 5 Mar 2020 14:58:45 +0100 Subject: [PATCH] Remove vms field from vmhost Signed-off-by: Nico Schottelius --- .../migrations/0003_remove_vmhost_vms.py | 17 +++++++++++++++++ uncloud/uncloud_vm/models.py | 8 +++----- uncloud/uncloud_vm/serializers.py | 3 +++ 3 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 uncloud/uncloud_vm/migrations/0003_remove_vmhost_vms.py diff --git a/uncloud/uncloud_vm/migrations/0003_remove_vmhost_vms.py b/uncloud/uncloud_vm/migrations/0003_remove_vmhost_vms.py new file mode 100644 index 0000000..70ee863 --- /dev/null +++ b/uncloud/uncloud_vm/migrations/0003_remove_vmhost_vms.py @@ -0,0 +1,17 @@ +# Generated by Django 3.0.3 on 2020-03-05 13:58 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('uncloud_vm', '0002_auto_20200305_1321'), + ] + + operations = [ + migrations.RemoveField( + model_name='vmhost', + name='vms', + ), + ] diff --git a/uncloud/uncloud_vm/models.py b/uncloud/uncloud_vm/models.py index 41a1e93..3f07e1e 100644 --- a/uncloud/uncloud_vm/models.py +++ b/uncloud/uncloud_vm/models.py @@ -41,11 +41,9 @@ class VMHost(models.Model): max_length=32, choices=STATUS_CHOICES, default=STATUS_DEFAULT ) - # List of VMs running on this host - vms = models.TextField(default='') - - def get_vms(self): - return self.vms.split(',') + @property + def vms(self): + return VMProduct.objects.filter(vmhost=self) class VMProduct(Product): diff --git a/uncloud/uncloud_vm/serializers.py b/uncloud/uncloud_vm/serializers.py index 3bb9298..7302116 100644 --- a/uncloud/uncloud_vm/serializers.py +++ b/uncloud/uncloud_vm/serializers.py @@ -13,9 +13,12 @@ GB_HDD_PER_DAY=0.0006 class VMHostSerializer(serializers.ModelSerializer): + vms = serializers.PrimaryKeyRelatedField(many=True, read_only=True) + class Meta: model = VMHost fields = '__all__' + read_only_fields = [ 'vms' ] class VMDiskProductSerializer(serializers.ModelSerializer):