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): class User(AbstractUser):
""" """
We use the standard user and add a maximum negative credit that is allowed We use the standard user and add a maximum credit that is allowed
to be accumulated to be accumulated. After that we need to have warnings, cancellation, etc.
""" """
maximum_credit = models.DecimalField( maximum_credit = models.DecimalField(

View file

@ -186,4 +186,6 @@ class VMSnapshotProduct(Product):
gb_ssd = models.FloatField(editable=False) gb_ssd = models.FloatField(editable=False)
gb_hdd = 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,15 +32,19 @@ class VMDiskImageProductSerializer(serializers.ModelSerializer):
fields = '__all__' fields = '__all__'
class VMProductSerializer(serializers.ModelSerializer): class VMProductSerializer(serializers.ModelSerializer):
class Meta:
model = VMProduct
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. # Custom field used at creation (= ordering) only.
recurring_period = serializers.ChoiceField( recurring_period = serializers.ChoiceField(
choices=VMProduct.allowed_recurring_periods()) choices=VMProduct.allowed_recurring_periods())
class Meta: snapshots = serializers.PrimaryKeyRelatedField(many=True,
model = VMProduct read_only=True)
fields = ['uuid', 'order', 'owner', 'status', 'name', \
'cores', 'ram_in_gb', 'recurring_period']
read_only_fields = ['uuid', 'order', 'owner', 'status']
class DCLVMProductSerializer(serializers.HyperlinkedModelSerializer): class DCLVMProductSerializer(serializers.HyperlinkedModelSerializer):