diff --git a/uncloud/uncloud_auth/models.py b/uncloud/uncloud_auth/models.py index aef1e20..c3a0912 100644 --- a/uncloud/uncloud_auth/models.py +++ b/uncloud/uncloud_auth/models.py @@ -8,8 +8,8 @@ from uncloud_pay.models import get_balance_for_user class User(AbstractUser): """ - We use the standard user and add a maximum negative credit that is allowed - to be accumulated + We use the standard user and add a maximum credit that is allowed + to be accumulated. After that we need to have warnings, cancellation, etc. """ maximum_credit = models.DecimalField( diff --git a/uncloud/uncloud_vm/models.py b/uncloud/uncloud_vm/models.py index 70ffd80..57b54cf 100644 --- a/uncloud/uncloud_vm/models.py +++ b/uncloud/uncloud_vm/models.py @@ -186,4 +186,6 @@ class VMSnapshotProduct(Product): gb_ssd = models.FloatField(editable=False) gb_hdd = models.FloatField(editable=False) - vm = models.ForeignKey(VMProduct, on_delete=models.CASCADE) + vm = models.ForeignKey(VMProduct, + related_name='snapshots', + on_delete=models.CASCADE) diff --git a/uncloud/uncloud_vm/serializers.py b/uncloud/uncloud_vm/serializers.py index 75bcabe..f759d01 100644 --- a/uncloud/uncloud_vm/serializers.py +++ b/uncloud/uncloud_vm/serializers.py @@ -32,16 +32,20 @@ class VMDiskImageProductSerializer(serializers.ModelSerializer): fields = '__all__' class VMProductSerializer(serializers.ModelSerializer): - # Custom field used at creation (= ordering) only. - recurring_period = serializers.ChoiceField( - choices=VMProduct.allowed_recurring_periods()) - class Meta: model = VMProduct - fields = ['uuid', 'order', 'owner', 'status', 'name', \ - 'cores', 'ram_in_gb', 'recurring_period'] + fields = ['uuid', 'order', 'owner', 'status', 'name', + 'cores', 'ram_in_gb', 'recurring_period', + 'snapshots' ] read_only_fields = ['uuid', 'order', 'owner', 'status'] + # Custom field used at creation (= ordering) only. + recurring_period = serializers.ChoiceField( + choices=VMProduct.allowed_recurring_periods()) + + snapshots = serializers.PrimaryKeyRelatedField(many=True, + read_only=True) + class DCLVMProductSerializer(serializers.HyperlinkedModelSerializer): """