From 2910a3229a153bfae0f6b7735d7e973e145e3829 Mon Sep 17 00:00:00 2001 From: catborise Date: Tue, 23 Aug 2022 08:42:19 +0300 Subject: [PATCH] apply recommendation of code-review-doctor --- instances/models.py | 18 +++++++++--------- networks/api/serializers.py | 7 ------- storages/models.py | 20 ++++++++++---------- 3 files changed, 19 insertions(+), 26 deletions(-) diff --git a/instances/models.py b/instances/models.py index cc15873..fa18483 100644 --- a/instances/models.py +++ b/instances/models.py @@ -210,16 +210,16 @@ class Instance(models.Model): class MigrateInstance(models.Model): - instance = models.ForeignKey(Instance, on_delete=models.DO_NOTHING) - target_compute = models.ForeignKey(Compute, related_name='target', on_delete=models.DO_NOTHING) + instance = models.ForeignKey(Instance, related_name='source_host', on_delete=models.DO_NOTHING) + target_compute = models.ForeignKey(Compute, related_name='target_host', on_delete=models.DO_NOTHING) - live = models.BooleanField(_('Live'), blank=False) - xml_del = models.BooleanField(_('Undefine XML'), blank=False, default=True) - offline = models.BooleanField(_('Offline'), blank=False) - autoconverge = models.BooleanField(_('Auto Converge'), blank=False, default=True) - compress = models.BooleanField(_('Compress'), blank=False, default=False) - postcopy = models.BooleanField(_('Post Copy'), blank=False, default=False) - unsafe = models.BooleanField(_('Unsafe'), blank=False, default=False) + live = models.BooleanField(_('Live')) + xml_del = models.BooleanField(_('Undefine XML'), default=True) + offline = models.BooleanField(_('Offline')) + autoconverge = models.BooleanField(_('Auto Converge'), default=True) + compress = models.BooleanField(_('Compress'), default=False) + postcopy = models.BooleanField(_('Post Copy'), default=False) + unsafe = models.BooleanField(_('Unsafe'), default=False) class Meta: managed = False diff --git a/networks/api/serializers.py b/networks/api/serializers.py index 8b26298..347d1db 100644 --- a/networks/api/serializers.py +++ b/networks/api/serializers.py @@ -10,10 +10,3 @@ class NetworksSerializer(serializers.ModelSerializer): fields = ['name', 'status', 'device', 'forward'] - -# class VolumeSerializer(serializers.ModelSerializer): -# allocation = serializers.ReadOnlyField() -# meta_prealloc = serializers.BooleanField(write_only=True) -# class Meta: -# model = Volume -# fields = ['name', 'type', 'allocation', 'size', 'meta_prealloc'] diff --git a/storages/models.py b/storages/models.py index 0af474b..fdca3bf 100644 --- a/storages/models.py +++ b/storages/models.py @@ -9,12 +9,12 @@ class Storages(models.Model): size = models.IntegerField(_('size')) volumes = models.IntegerField(_('volumes')) - def __str__(self): - return f'{self.name}' - class Meta: managed = False + def __str__(self): + return f'{self.name}' + class Volume(models.Model): name = models.CharField(_('name'), max_length=128) @@ -22,13 +22,13 @@ class Volume(models.Model): allocation = models.IntegerField(_('allocation')) size = models.IntegerField(_('size')) - def __str__(self): - return f'{self.name}' - class Meta: managed = False verbose_name_plural = "Volumes" + def __str__(self): + return f'{self.name}' + class Storage(models.Model): state = models.IntegerField(_('state')) @@ -38,10 +38,10 @@ class Storage(models.Model): path = models.CharField(_('path'), max_length=128) type = models.CharField(_('type'), max_length=128) autostart = models.BooleanField(_('autostart')) - volumes = models.ForeignKey(Volume, on_delete=models.DO_NOTHING) - - def __str__(self): - return f'{self.path}' + volumes = models.ForeignKey(Volume, related_name="storage_volumes", on_delete=models.DO_NOTHING) class Meta: managed = False + + def __str__(self): + return f'{self.path}'