Also list snapshots for a VM

This commit is contained in:
Nico Schottelius 2020-03-18 15:19:06 +01:00
parent c6a9bd4363
commit 4b4cbbf009
3 changed files with 15 additions and 9 deletions

View file

@ -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(

View file

@ -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)

View file

@ -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):
"""